Niris
2013-08-07 16:35:00 +08:00
The browser will not queue up more than one instance of a specific interval handler.
-- Secrets of the JavaScript Ninja
When using setInterval(), timer code is added to the queue only if there are no other instances of the timer code already in the queue.
--PROFESSIONAL JAVASCRIPT
两本书都这么说的。
可以试试下面的代码输出几个 interval
var i = window.setInterval(function() {
console.log('interval', Date.now());
}, 1000);
window.setTimeout(function() {
window.clearInterval(id);
console.log('stop', Date.now());
}, 5900);
var t = Date.now() + 5000;
while(Date.now() < t) {
console.log(1);
}