Created
May 19, 2015 15:16
-
-
Save piyonishi/d49d4af68b738f81364b to your computer and use it in GitHub Desktop.
クロージャ
This file contains hidden or 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 newCounter() { | |
var i = 0; | |
return function() { | |
i = i + 1; | |
return i; | |
} | |
} | |
var c1 = newCounter(); | |
var c2 = newCounter(); | |
console.log(c1()); // 1 | |
console.log(c1()); // 2 | |
console.log(c2()); // 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment