【发布时间】:2016-04-28 03:32:21
【问题描述】:
var timeout = setTimeout(function(){
console.log("I'm message from timeout");
},0);
console.log("I'm message from outside timeout");
//1. I'm message from outside timeout
//2. I'm message from timeout
为什么尽管将 setTimeout 时间设置为 0,但内部指令不首先执行?我使用了各种时间,包括 0/null,我想知道如何保留 setTimeout 对象并随流程执行其指令。
【问题讨论】:
-
setTimeout always 被推迟到 JavaScript 的 下一个“执行时间”。值 0/null 不会改变这一点(在现代浏览器中被视为值 5)。
-
我在这里写了一个长答案:stackoverflow.com/questions/32580940/… 并且可能还有很多其他相关问题
-
你应该看看这个:youtube.com/watch?v=8aGhZQkoFbQ
标签: javascript settimeout