CSC/ECE 517 Fall 2011/ch3 4b js: Difference between revisions
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
== Closures == | == Closures == | ||
===What is a Closure?=== | ===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 as essentially a function pointer that references a block of executable code and the variables from the scope it was created. | |||
===Closures in Ruby=== | ===Closures in Ruby=== | ||
====Blocks==== | ====Blocks==== |
Revision as of 03:49, 15 October 2011
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 as essentially a function pointer that references a block of executable code and the variables from the scope it was created.