每次提到closure首先想到的都是「Friends」里Rachel喝高了给Ross留语音的这个场景.. 🙂

好了当然我说的不是这个。
Closures are functions that refer to independent (free) variables. In other words, the function defined in the closure ‘remembers’ the environment in which it was created.
A closure is an inner function that has access to the outer (enclosing) function’s variables—scope chain. The closure has three scope chains:
- it has access to its own scope (variables defined between its curly brackets)
- it has access to the outer function’s variables
- it has access to the global variables.
The inner function has access not only to the outer function’s variables, but also to the outer function’s parameters. Note that the inner function cannot call the outer function’s arguments object, however, even though it can call the outer function’s parameters directly.


