CSC/ECE 517 Fall 2011/ch3 4b js: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 4: Line 4:
*A closure can be passed as an object.
*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 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.
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.


===Closures in Ruby===  
===Closures in Ruby===  

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 simply as a function pointer that references a block of executable code and the variables from the scope it was created.

Closures in Ruby

Blocks

Procs and Lambdas

Why use Closures?

Currying

Object-Oriented Programming in Ruby

Classes

Attributes

Inheritance

Access Control

Abstract Methods