Skip to content

Instantly share code, notes, and snippets.

@benlieb
Last active December 31, 2015 14:39
Show Gist options
  • Save benlieb/8001360 to your computer and use it in GitHub Desktop.
Save benlieb/8001360 to your computer and use it in GitHub Desktop.
function F() {
var arr = [], i;
for (i = 0; i < 3; i++) {
arr[i] = (function (x) {
return function () {
return x; };
}(i)); }
return arr; }
This gives you the expected result:
> var arr = F(); > arr[0]();
0
> arr[1]();
1
> arr[2]();
2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment