先看代码
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(4)
})
.then(()=>{
console.log(5)
})
.then(()=>{
console.log(6)
})
须知: .then 是一个微任务,会将回调函数加入到微队列
1.promiseA+规范
只要一调用.then 方法就没有任何商量余地,一定会产生一个新的promise
当.then 函数返回的是一个promise的时候当前的promise的状态由回调函数来决定
2.源码
如果返回的是一个promise那么它会去调用.then方法,并且放到微队列里去做(代码中return)
输出结果

