Closures and Other Great Powers of Functions in Javascript
October 14, 2011 in Web Development  Edit: I originally created
this post to explain how you can use functions in Javascript and
misunderstood the term “closure”. The examples are still valid
and good examples of how to use functions as first-class
citizens, but technically, most of them are not using “closures”
– I was using the term too broadly. I got a great comment from
Venkman who explained the term more accurately. Thank you
Venkman  Javascript is an incredibly powerful language. There
are many very interesting aspects to it, but one of it’s most
useful and powerful features are it’s closures.  What are
closures?  Wikipedia probably has a deeper and more accurate
explanation for what a closure is, but in words that I would be
able to understand:  Closures are functions that you define “on
the fly” that have access to the same variables (the same scope)
as they get defined in. You can store them as variables, pass
them around between other funct