Skip to content

Instantly share code, notes, and snippets.

@mightyguava
Last active March 12, 2017 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mightyguava/9548467033dcc987be79a02fb9516b77 to your computer and use it in GitHub Desktop.
Save mightyguava/9548467033dcc987be79a02fb9516b77 to your computer and use it in GitHub Desktop.
Demystifying Async Programming in Javascript - Generator internals makeCounter() closure
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