我知道
promise 3
被拒绝是因为它解决了一个 已经被拒绝的承诺 (promise 2
),但是 promise 3
怎么会拒绝 promise 4
?, 幕后发生了什么?
Promise.resolve(6) // promise 1
.then(function(data) {
console.log('then 1:' + data);
return Promise.reject(new Error('ups - rejected')); // Does it "jump" to the first catch() it finds?
}) // promise 2 - this promise is resolved with a **rejected promise**
.then(function (data) {
console.log('then 2:' + data);
return data + 1;
}) // promise 3
.then(function (data) {
console.log('then 3:' + data);
return data + 1;
}) // promise 4
.catch(function(error) { // catch of promise 4?
console.log(error);
});
输出:
then 1:6
index.js:57 Error: ups - rejected
at index.js:46:27