路过的大佬,下面的执行顺序为什么是 0 1 2 3 4 5 6,而不是 0 1 4 2 3 5 6啊,救救孩子吧😭
Promise.resolve().then(() => {
console.log(0)
return Promise.resolve(4);
}).then((res) => {
console.log(res)
})
Promise.resolve().then(() => {
console.log(1)
}).then(() => {
console.log(2)
}).then(() => {
console.log(3)
}).then(() => {
console.log(5)
}).then(() => {
console.log(6)
})
问题在于 return Promise.resolve(4); 是返回的 Promise 对象 导致被延后了。
你 return 4;
就是 0 1 4 2 3 5 6 了。