CSC/ECE 517 Fall 2011/ch3 4b js

From Expertiza_Wiki
Jump to navigation Jump to search

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.

Closures in Ruby

Blocks

Procs and Lambdas

Why use Closures?

Currying

Object-Oriented Programming in Ruby

Classes

Attributes

Inheritance

Access Control

Abstract Methods