Skip to content

Instantly share code, notes, and snippets.

@tarnacious
Created November 29, 2010 06:59
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 tarnacious/719672 to your computer and use it in GitHub Desktop.
Save tarnacious/719672 to your computer and use it in GitHub Desktop.
// I always thought this really interesting in JavaScript, and doesn't seem to work the same in C# or Python.
get_counter = function() {
var counter = 0;
return function() {
print(counter); counter++;
}
};
..
js> counter1 = get_counter();
..
js> counter1();
0
js> counter1();
1
js> counter2 = get_counter();
..
js> counter2()
0
js> counter1()
2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment