We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
微任务的优先级高于宏任务
The text was updated successfully, but these errors were encountered:
比如下面的代码,每个输出语句在第几次事件循环中执行的呢?
console.log(1); setTimeout(() => { console.log(2); }, 0); let promise = new Promise((res) => { console.log(3); resolve(); }) .then((res) => { console.log(4); }) .then((res) => { console.log(5); }); console.log(6); // 1 3 6 4 5 2
Sorry, something went wrong.
在一个事件循环内,先执行宏任务,再执行本次宏任务中所有的微任务.script代码段整体是一个宏任务,从上至下执行.输出1以后输出3.console.log(3);虽然在promise里面,但是依然是同步代码,遇到resolve();将.then的内容添加到微任务队列,继续执行console.log(6);,至此本次事件循环中宏任务全部执行完毕,执行微任务中的console.log(4);执行完后将. then再加入本次宏任务的微任务队列,继续执行console.log(5);.至此本次事件循环中的微任务执行完毕.进行下一轮事件循环,console.log(2);
console.log(3);
resolve();
console.log(6);
console.log(4);
console.log(5);
console.log(2);
No branches or pull requests
微任务的优先级高于宏任务
The text was updated successfully, but these errors were encountered: