技术要点

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