Skip to content

Instantly share code, notes, and snippets.

@mapiondev
Created June 8, 2010 00:38
Show Gist options
  • Save mapiondev/429432 to your computer and use it in GitHub Desktop.
Save mapiondev/429432 to your computer and use it in GitHub Desktop.
[javascript] クロージャ
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