Last active
December 31, 2015 14:39
-
-
Save benlieb/8001360 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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