【发布时间】:2017-09-07 02:43:02
【问题描述】:
是否有可能在循环执行块之后调用延迟为 0 毫秒 setTimeout(function, 0) 的超时函数,或者是否会先完成包含函数块总是?
setTimeout(function(){ //something in here }, 0);
function myFunction() {
// do something
// loop block
// could timeout = 0 be scheduled to execute here?
// do more things
}
myFunction()
在我的上下文中(Angular 2),在我完成操作嵌套中的双向绑定属性之前,了解是否可以调用 Angular 的 ApplicationRef.tick() 来检查数据绑定/组件更改会很有趣循环?
函数调用和所有后续子函数调用是否等同于消息队列中的单个项目,还是分解为每个执行块作为消息队列中的单个项目?因此setTimeout(..., 0) 可能进入队列中的执行块之间?
【问题讨论】:
-
如果你想了解更多关于 JS 调用栈以及为什么异步代码在同步代码运行完成后总是被调用,我鼓励你watch this great talk。
标签: javascript angular settimeout nonblocking