CSC/ECE 517 Fall 2011/ch3 4b js
Closures
What is a Closure?
A closure is a block of code that can access the lexical environment of its definition. A closure has two properties:
- A closure can be passed as an object.
- A closure recalls the values of all the variables that were in scope when the function was created and is able to access those variables when it is called even though they may no longer be in scope.
A closure can be expressed simply as a function pointer that references a block of executable code and the variables from the scope it was created.