坏小仔

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

setTimeout(function() { #1
/* Some long block of code... */ #1
setTimeout(arguments.callee, 10); #1
}, 10); #1
setInterval(function() { #2
/* Some long block of code... */ #2
}, 10); #2
#1 Sets up a timeout that reschedules itself
#2 Sets up an interval

The two pieces of code in listing 8.1 may appear to be functionally equivalent, but they
are not. Notably the setTimeout variant of the code will always have at least a 10ms delay
after the previous callback execution (it may end up being more, but never less), whereas
the setInterval will attempt to execute a callback every 10ms regardless of when the last
callback was executed.

posted on 2012-08-21 17:05  坏小仔  阅读(152)  评论(0编辑  收藏  举报