多个 setTimeout 的执行顺序没有角度延迟 [英] Execution order of multiple setTimeout without delays in angular

查看:69
本文介绍了多个 setTimeout 的执行顺序没有角度延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

angular2+中多个setTimeout无延迟的执行顺序是什么?

What is the execution order of multiple setTimeout without delays in angular2+?

示例:

setTimeout(() => console.log('1'));
setTimeout(() => console.log('2'));

问题:

(1) 1 是否总是保证在 2 之前打印?
(2) 如果是这样,规范的哪一部分是这样说的?
(3) 这在 Angular2+ 代码中调用.角度是否覆盖 setTimeout 的默认行为?

(1) Is 1 always guaranteed to be printed before 2?
(2) If so, what part of the spec says so?
(3) This is called in Angular2+ code. Is angular overriding setTimeout's default behaviour?

它与其他问题的区别:

这个问题 (1) 立即询问案例,(2) 在 angular 上下文中询问(以防 angular 覆盖 setTimeout).

This question (1) asks about the case without delay, and (2) asks it in angular context (in case angular overrides setTimeout).

非问题:

我知道 console.log 可能(也可能不是)是异步的或其他什么;这个问题与此无关.您可以假设 console.log 是同步的.

I know console.log might (or might not) be async or whatever; this question is not related to that. You can assume console.log is sync.

推荐答案

1) 是

2) https://html 的第 16 步.spec.whatwg.org/multipage/timers-and-user-prompts.html 其中说:

等待直到对该算法的任何调用具有相同的方法上下文,在此之前开始,并且其超时等于或少于这个,已完成.

Wait until any invocations of this algorithm that had the same method context, that started before this one, and whose timeout is equal to or less than this one's, have completed.

3) 不,Angular 不会覆盖它.

3) No, Angular does not override it.

这篇关于多个 setTimeout 的执行顺序没有角度延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆