Created
August 8, 2009 05:19
-
-
Save masuidrive/164309 to your computer and use it in GitHub Desktop.
This file contains 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
var funcs = []; | |
for(var i=0; i<10; ++i) { | |
funcs[i] = function() { console.log(i); } | |
} | |
i = -1; | |
for(var ii=0; ii<10; ++ii) funcs[ii](); | |
// -1が10回表示 | |
var funcs = []; | |
for(var i=0; i<10; ++i) { | |
funcs[i] = function(j){ return function(){ console.log(j); }}(i); | |
} | |
i = -1; | |
j = -1; | |
for(var ii=0; ii<10; ++ii) funcs[ii](); | |
// 0-9を表示 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment