Skip to content

Instantly share code, notes, and snippets.

@inklesspen
Created June 20, 2009 00:10
Show Gist options
  • Save inklesspen/132963 to your computer and use it in GitHub Desktop.
Save inklesspen/132963 to your computer and use it in GitHub Desktop.
var foo = function() {
var funcs = [];
for (var i=0; i < 5; i++) {
funcs[i] = function() {alert("The number is " + i);};
}
return funcs
};
var f = foo()
f[0](); // You will expect this to show a box with 0
f[4](); // And this to show a box with 4. But they both show 5.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment