疑问

1.【setInterval定时器】为什么加了count后没有阻塞定时器。

var startTime = +new Date;
var count = 0;
var handle = setInterval(function() {
  console.log('hello world');
  count++;
  if(count === 1000) clearInterval(handle);
}, 10);

while(+new Date - startTime < 10 * 1000) {};

以上代码返回结果是输出1000次hello world,如下代码,首次输出一个hello world,没有连续三个。

var startTime = +new Date;

var handle = setInterval(function() {
  console.log('hello world');
}, 3000);

while(+new Date - startTime < 10 * 1000) {};
原文地址:https://www.cnblogs.com/lixuemin/p/9239993.html