Created
October 10, 2016 02:44
-
-
Save hoosin/4367b9259eb6a46d32d8772bf999083b to your computer and use it in GitHub Desktop.
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 func() { | |
var i = 0; | |
return function () { | |
return i++; | |
} | |
} | |
var counter = func(); | |
console.log(counter()); // 0 | |
console.log(counter()); // 1 | |
console.log(counter()); // 2 | |
console.log(counter()); // 3 | |
console.log(counter()); // 4 | |
counter = func(); | |
console.log(counter()); // 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment