技术要点
- 要在 Promise 上写而不是在原型上写
- all 的参数(Promise 数组)和返回值(新 Promise 对象)
- 用数组来记录结果
- 只要有一个 reject 就整体 reject
Promise.myAll = function(list){const results = []let count = 0list.map((item, index)=> {item.then(result=>{results[index] = resultcount += 1if (count >= list.length) { resolve(results)}}, reason => reject(reason) )})})}
