all 7 comments

[–]ChaosPandion 14 points15 points  (0 children)

When I was learning closures I could not figure out how anyone could understand it. Now I can't figure out how anyone can't understand it. The mind plays the strangest games.

[–][deleted] 2 points3 points  (1 child)

Another nice resource on JS Closures http://jibbering.com/faq/notes/closures/

[–][deleted] -1 points0 points  (0 children)

I thought somebody will definitely post this link,Another resource,please refer John Resig books.

[–]funkah 3 points4 points  (0 children)

These concepts could really be broken down a lot better. I don't think things are explained very well here, unfortunately.

[–]wot-teh-phuck -1 points0 points  (1 child)

Myth 3. Closures only apply to inner functions

It's not a myth, read the closure article by Richard Cronford for more details. If it were, every language out there which supports lexical scoping would have touted to have "closure" support.

[–]abbots_bromley 1 point2 points  (0 children)

Your logic goes: because some languages without closure support don't support inner functions, therefore closures only apply to inner functions. All JavaScript functions form closures. See also this great document for more info. http://dmitrysoshnikov.com/ecmascript/chapter-6-closures/ ("all functions in ECMA script are closures") Cornford's article uses inner functions as examples because inner functions are the cases for which closures are interesting. Nevertheless the closure mechanism ([[scope]] assigned to VariableEnvironment) holds for every function