http://ejohn.org/blog/how-javascript-timers-work 这是John的一篇博文说到setTimeout和setInterval的区别,在看js高效图形编程的时候文中提到的. 首先很明显的是: 1. setTimeout是定时触发,在一定的延时后只触发一次,但是可以利用回调一个setTimeout来实现循环触发,比如: setTimeout(function(){ /* Some long block of code... */ setTimeout(ar…
// numberMillis 毫秒 function sleep(numberMillis) { var now = new Date(); var exitTime = now.getTime() + numberMillis; while (true) { now = new Date(); if (now.getTime() > exitTime){ return; } } }…