Glossary: Closure

A "closure" is a function that has data intrinsically bound to it, for instance by virtue of where it's defined. This is a closure:

var a;
a = 5;
function myFunction()
    // ...

"myFunction" is a closure: The 'a' variable is bound to it, because 'a' is in scope where 'myFunction' is defined. There's also a closure here:
var a;
a = ['a', 'b', 'c'];
a.each(function(v) {

The anonymous function used with the each method is a closure.

More on closures:

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License