老师,这里p1状态应该是rejected,为什么console.log打印出来是fulfilled?
来源:8-8 Promise的then和catch如何影响状态的变化

Tender_DongGua
2021-06-25
const p1 = Promise.resolve().then(() => {
throw new Error(‘err’)
}).catch(()=>{
console.log(1)
})
p1.then(()=>{
console.log(2)
throw new Error(‘err’)
})
console.log(p1) //fulfilled
//我发现console.log(p1) 只认第一次连写的结果
写回答
1回答
-
错了,p1 是 fulfilled ,因为你写了 const p1 = Promise.resolve()
你所认为的 rejected 的并不是 p1 ,而是 p1.then(...) 返回的值,例如:
const p2 = p1.then(....)
console.log(p2)
012021-06-25
相似问题