Last active
March 12, 2017 18:48
-
-
Save mightyguava/9548467033dcc987be79a02fb9516b77 to your computer and use it in GitHub Desktop.
Demystifying Async Programming in Javascript - Generator internals makeCounter() closure
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 makeCounter() { | |
var count = 1; | |
return function () { | |
return count++; | |
} | |
} | |
var counter = makeCounter(); | |
console.log(counter()); // 1 | |
console.log(counter()); // 2 | |
console.log(counter()); // 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment