Skip to content

Instantly share code, notes, and snippets.

@mre
Created September 5, 2011 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mre/1195585 to your computer and use it in GitHub Desktop.
Save mre/1195585 to your computer and use it in GitHub Desktop.
Closures in JavaScript
function getCtr() {
var i = 0; return function() { console.log(++i); }
}
var ctr = getCtr()
ctr() // 1
ctr() // 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment