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?
业精于勤,荒于嬉;行成于思,毁于随。
Your js is so wrong
for(var i=1;i<=10;i++){ (function(i){ setTimeout(function(){ console.log(i); },1000*i) })(i) }
Your js is so wrong