by hammerha on 3/18/13, 7:08 AM with 18 comments
by tomp on 3/18/13, 8:30 AM
Any function that has free variables that are not global variables is a closure. Another way to think about it: any function that cannot be implemented in C is a closure.
So, in these examples, the inner functions are closures, the outer ones are not, but only because the outer ones are used in a global scope. If you enclosed everything in another function, then also the outer functions would be closures.
by AlexanderDhoore on 3/18/13, 9:54 AM
Only read the 3.2 part, it's not long: http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-21.html...
by just2n on 3/18/13, 8:42 AM
The accepted answer also overcomplicates what could be a very simple answer.
In a quick Google, I found this. Asked in '08, not '12: http://stackoverflow.com/questions/111102/how-do-javascript-...
by lhnz on 3/18/13, 1:14 PM
If you're accessing a local variable from a different function scope than it was created in then you are using a closure - there is nothing special about how it was defined, this is the only distinction.
by hayksaakian on 3/18/13, 7:38 AM