若 onFulfilled 、onRejected 返回一个非promise对象、非thenable对象的值 x ,则 promise2 的状态为 fulfilled ,终值为 x
let p = new Promise((resolve,reject)=>{ throw new Error();});let p1 = p.then(null,(data)=>{ return '我是p2的终值'});p1.then((data)=>{ console.log(data)});// print: 我是p2的终值
若 onFulfilled 、onRejected 返回一个 promise 对象的值 x ,promise2 的状态、终值、拒因与 x 同步
let p1 = new Promise((resolve,reject)=>{ resolve(1)})let p2 = new Promise((resolve,reject)=>{ reject(2)})let p3 = new Promise((resolve)=>{ resolve()})let p4 = p3.then(()=>{ return p1;})let p5 = p3.then(()=>{ return p2;})// p4 的状态为 fulfilled 终值为 1// p5 的状态为 rejected 拒因为 2
若 onFulfilled 或者 onRejected 抛出一个异常 e ,则 promise2 的状态为 rejected,拒因为 e
let p = new Promise((resolve,reject)=>{ resolve();});let p1 = p.then((data)=>{ throw new Error('error')});p1.then(null,(err)=>{ console.log(err);});// print: Error: error
let p = new Promise((resolve,reject)=>{ resolve('我是p的终值');});let p1 = p.then((data)=>{ throw new Error('异常')});p1.then(null,(err)=>{ console.log(err);});// print:Error: 异常 终值和拒因的穿透特性