多个异步操作,如果中间出现reject后面应该不会再执行,
为什么下面代码中第二个then函数还会执行?
function getJson(idx){
return new Promise(function(resolve,reject){
setTimeout(function(){
var random = Math.floor(Math.random() * 1000);
console.log('success'+random);
reject(random);
},1000)
})
}
getJson(13).then(function(){
return getJson(14);
},function(){
console.log(arguments)
return "adas";
}).then(function(){
return getJson(15);
}).then(function(){
return getJson(16);
})
https://developer.mozilla.org...返回值
第一个then执行onRejected,返回一个resolved Promise,第二个then执行,但是第二个then没有onRejected,所以简单地采用 Promise 的拒绝状态