js执行顺序题(chrome浏览器)
async function async1() {
console.log('async1 start')
await async2()
console.log('async1 end')
}
async function async2() {
console.log('async2')
}
console.log('script start')
setTimeout(function () {
console.log('setTimeout')
}, 0)
async1();
new Promise((resolve) => {
console.log('promise1')
resolve();
}).then(() => {
console.log('promise2')
})
代码执行结果为
script start
async1 start
async2
promise1
promise2
async1 end
setTimeout
大神帮忙分析下为什么promise2会比async1 end 先执行呢?
在 Chrome73(金丝雀) 版本之后,async 的执行优化了,即新版已经不存在这个问题了。
也有人认为这是违背了规范,详见https://juejin.im/post/5e5c7f...