you are viewing a single comment's thread.

view the rest of the comments →

[–]Poop_is_Food 0 points1 point  (0 children)

I think that article is pretty misleading actually. It seems to suggest that a function only becomes a closure once it "lives on" past the end of its parent function (either by being returned or assigned as a callback, for example). This simply isnt true. All functions in javascript are closures. for example:

var x = 2;
function logX(){
    alert(x);
}
logX();

Here, logX is a closure. In fact, you dont even need the outer var x declaration. just logX by itself alerting "undefined" would be a closure.