let p1 = new Promise((resolve,reject)=>{
//resolve('resolve')
reject('reject')
});
p1.then(a=>{
console.log(a);
},b=>{
console.log(b);
return 1;
}).then(a=>{
console.log(a); // 1
})
注意:1.then返回非promise对象始终是resolved状态 并且传递给下一个then的值为return 的值
2.有then方法的普通对象也是promise对象
let p2 = new Promise((resolve,reject)=>{
//resolve('resolve')
reject('reject')
});
p2.then(a=>{
console.log(a);
},b=>{
console.log(b);
return new Promise((resolve,reject)=>{
//reject('reject');
resolve('resolve');
})
}).then(a=>{
console.log(a); // resolve
},b=>{
console.log(b); // reject
})
注意:then返回的是promise对象则正常处理
promise对象:
1:new promise()
2:{
then(resolve,reject){
resolve('resolve')
}
}