Skip to content

Instantly share code, notes, and snippets.

@git2samus
Created May 22, 2012 17:49
Show Gist options
  • Select an option

  • Save git2samus/2770557 to your computer and use it in GitHub Desktop.

Select an option

Save git2samus/2770557 to your computer and use it in GitHub Desktop.
> function integerFactory() {
var n=0;
return function() {
return n++;
};
};
undefined
> next_integer = integerFactory();
function () { return n++; }
> next_integer();
0
> next_integer();
1
> next_integer();
2
> next_integer2 = integerFactory();
function () { return n++; }
> next_integer2();
0
> next_integer();
3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment