Skip to content

Instantly share code, notes, and snippets.

@rsliter
Created December 3, 2012 18:15
Show Gist options
  • Select an option

  • Save rsliter/4196824 to your computer and use it in GitHub Desktop.

Select an option

Save rsliter/4196824 to your computer and use it in GitHub Desktop.
Closures in JavaScript and Ruby

I put together a handful of gists in order to dip my toes into functional programming and understand exactly how closures in both JavaScript and Ruby work.

Definition of a closure

A closure is a function that can be passed around in order to be called later. Its other property (the one that screws programmers up :) is the fact that the variable values persist from the time the function is created. It can then access the variables even after they lose scope/change values.

My explanations and examples:

Closures in JavaScript: https://gist.github.com/45ba3ef454d9696d2bb5
Closures in Ruby: https://gist.github.com/4196841

References:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment