对How JavaScript Timers Work的理解
John Resig在How JavaScript Timers Work一文中,对setTimeout和setInterval的分析很精辟:
总结如下:
- JavaScript engines only have a single thread, forcing asynchronous events to queue waiting for execution.
- setTimeout and setInterval are fundamentally different in how they execute asynchronous code.
- If a timer is blocked from immediately executing it will be delayed until the next possible point of execution (which will be longer than the desired delay).
- Intervals may execute back-to-back with no delay if they take long enough to execute (longer than the specified delay).
我的心得: 阅读全文 »

