//自调函数定时执行var i = 0;function fn(){ console.log(i); i++;}var timer = setInterval(function(){ if(i > 10) { clearInterval(timer); } else{ fn(); }},1000);//闭包立即执行队列for(var i = 0; i <= 10; i++ ) { (function(i){ setTimeout(function() { console.log(i) },i*1000) ; })(i)}
时间: 2024-10-27 13:52:39