JS中的sleep

//这种情况无法sleep,先输出xix,再输出FUCK3次
sec = 3;
int_id = setInterval(function(){
     sec--;
     alert("FUCK");
     if(sec <= 0) clearInterval(int_id);
},1000);
alert("xix");
 
//300毫秒后执行function中逻辑(不阻塞),先输出xix
setTimeout(function(){
  console.log("execute");
},300)
alert("xix");

 

posted @ 2013-12-19 17:23  apeipo  阅读(108)  评论(0)    收藏  举报