setTimeout方法注意事项
文章目录
Passing string literalsSection
Passing a string instead of a function to setTimeout() has the same associated problems as using eval.
// Recommended
window.setTimeout(function() {
alert('Hello World!');
}, 500);
// Not recommended
window.setTimeout("alert('Hello World!');", 500);
A string passed to setTimeout is evaluated in the global context, so local symbols in the context where setTimeout() was called will not be available when the string is evaluated as code.
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论