Created
September 5, 2011 18:09
-
-
Save mre/1195585 to your computer and use it in GitHub Desktop.
Closures in JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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