📜  在 js 中睡觉 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:01.448000             🧑  作者: Mango

代码示例2
function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}

//using sleep()
sleep(2000); //sleep for 2 seconds