Created
June 8, 2010 00:38
-
-
Save mapiondev/429432 to your computer and use it in GitHub Desktop.
[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 closure() { | |
var count = 0; | |
return function(plus) { | |
return count += plus; | |
}; | |
} | |
var close = closure(); | |
var plus1 = close(1); | |
var plus2 = close(2); | |
console.log(plus1); // 1 | |
console.log(plus2); // 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment