1const promise1 = new Promise((resolve, reject) => { 2 setTimeout(() => { 3 resolve('success') 4 }, 1000) 5}) 6const promise2 = promise1.then(() => { 7 throw new Error('error!!!') 8}) 9console.log('promise1', promise1) 10console.log('promise2', promise2) 11setTimeout(() => { 12 console.log('promise1', promise1) 13 console.log('promise2', promise2) 14}, 2000)
参考答案:
'promise1' Promise{<pending>}
'promise2' Promise{<pending>}
test5.html:102 Uncaught (in promise) Error: error!!! at test.html:102
'promise1' Promise{<resolved>: "success"}
'promise2' Promise{<rejected>: Error: error!!!}
最近更新时间:2024-07-20