前端_Promise面试题 2
题目一
如何改变Promise的状态?1、resolve(value):如果当前是pending就会变为resolved 2、reject(reason):如果当前是pending就会变为rejected 3、抛出异常:如果当前是pending就会变为rejected
const p = new Promise((resolve, reject) => {
throw new Error('出错了')
})
p.catch(reason => {console.log('reason' + reason)}) //reasonError: 出错了
const p = new Promise((resolve, reject) => {
throw 1
})
p.catch(reason => {console.log('reason' + reason)}) // reason1
题目二
一个Promise指定多个成功/失败回调函数,都会
共有 0 条评论