【发布时间】:2013-02-13 21:00:39
【问题描述】:
这是我的测试代码(小提琴here):
console.log('Before wait');
setTimeout(function () { console.log('Yo!'); }, 1000);
var start = Date.now();
while (Date.now() < start + 3000) {}
console.log('After wait');
这是 Chrome 中事件的时间线:
- 时间 0 秒:打印“等待前”
- 时间 3 秒:打印“等待后”,然后在“哟!”之后立即打印
这种行为是否符合规范?为什么没有
- 时间 0 秒:打印“等待前”
- 时间 3 秒:打印“等待后”
- 时间 4 秒:打印“Yo!”
?
【问题讨论】:
标签: javascript settimeout