坏小仔

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

Another way that we can cause strings of code to be evaluated, and in this case
asynchronously, is through the user of timers.
Normally, as we saw in chapter 8, we’d pass an inline function or a function reference to
a timer. This is the recommended usage of the setTimeout() and setInterval()
methods, But these methods also accept strings which will be evaluated when the timers fire.
For example:
var tick = window.setTimeout('alert("Hi!")',100);
It's rather rare that we would need to use this behavior (it's roughly equivalent to using
the new Function() approach) and it's use is discouraged at this point except in the
cases where the code to be evaluated must be a run-time string.

posted on 2012-08-22 17:03  坏小仔  阅读(93)  评论(0编辑  收藏  举报