在下面的代碼中,Promise.reject
不起作用,除非我專門使用return Promise.reject(...)
。爲什麼是這樣?爲什麼Promise.reject()需要返回?
Promise.resolve('Promise 1 Done')
.then(function(result) {
console.log(result);
return 'Promise 2 Done'
}).then(function(result) {
let j;
try {
j = JSON.parse("invalid will throw");
console.log(j);
} catch(err) {
Promise.reject('Could not parse JSON');
}
console.log(result);
}).catch(function(err) {
console.log(err);
});
什麼叫「不工作」是什麼意思? – martriay