一下两段代码单独执行或者同时执行的时候的打印顺序!
Promise.resolve()
.then(() => {
console.log(1);
Promise.resolve()
.then(() => {
console.log(3);
Promise.resolve()
.then(() => {
console.log(5);
Promise.resolve()
.then(() => {console.log(9)})
.then(() => console.log(10));
})
.then(() => console.log(6));
})
.then(() => console.log(4))
.then(() => console.log(8));
})
.then(() => console.log(2))
.then(() => console.log(7));
Promise.resolve()
.then(() => {
console.log(11);
Promise.resolve()
.then(() => {
console.log(13);
Promise.resolve()
.then(() => {
console.log(15);
Promise.resolve()
.then(() => {console.log(19)})
.then(() => console.log(110));
})
.then(() => console.log(16));
})
.then(() => console.log(14))
.then(() => console.log(18));
})
.then(() => console.log(12))
.then(() => console.log(17));
打印的数字就是顺序,本质就是Promise执行顺序而已,没有加
setTimeout
什么的函数,不涉及宏任务微任务优先级问题。两个一起执行无非是先执行上面的再执行下面的而已,理解了Promise执行顺序就行。这种题也就面试的时候会问到,背一下概念就行,其实没啥意义。