Promise.add 方法:將多個 promise 實例,包裝成一個新的 promise 實例。
const p = Promise.all([p1, p2, p3]);
接受一個數組作為參數,p1, p2, p3 都是 promise 實例,
const p1 = new Promise((resolve, reject) => { resolve('hello'); }).then(res => res); const p1 = new Promise((resolve, reject) => { throw new Error('報錯'); }).then(res => res); Promise.all([p1, p2]) .then(res => console.log(res)) .catch(e => console.log(e)) // Error : 報錯
