0,1,2になるところが、3が3回表示されてしまう。
for(var i = 0; i < 3; i++) {
setTimeout(function(){
alert(i);
}, 1000);
}
これで解決。
for(var i = 0; i < 3; i++) {
hoge(i);
}
function hoge(delay){
setTimeout(function(){
alert(delay);
}, 1000);
}
More than 5 years have passed since last update.
0,1,2になるところが、3が3回表示されてしまう。
for(var i = 0; i < 3; i++) {
setTimeout(function(){
alert(i);
}, 1000);
}
これで解決。
for(var i = 0; i < 3; i++) {
hoge(i);
}
function hoge(delay){
setTimeout(function(){
alert(delay);
}, 1000);
}
Register as a new user and use Qiita more conveniently