javascript - Solve the problem of closure and output it
迷茫
迷茫 2017-06-12 09:32:59
0
1
749
for (var i = 1; i <= 10; i++) {
  setTimeout({
    console.log(i);
  },2000*i);
}

I would like to ask how to use closure to solve the problem. It outputs 1 in the first second and 2 in the second second. . . And so on?

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(1)
typecho

Your js is so wrong

for(var i=1;i<=10;i++){
  (function(i){
    setTimeout(function(){
      console.log(i);
    },1000*i)
  })(i)
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template