KieSun / all-of-frontend

你想知道的前端内容都在这

Home Page:https://yuchengkai.cn/docs/frontend

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

顺序有问题

yancongwen opened this issue · comments

Promise.all = function(arr) {
  if(!Array.isArray(arr)) {
    throw new Error('参数必须是数组')
  }
  return new Promise((resolve, reject) => {
    const list = []
    arr.forEach(item => {
      this.resolve(item).then((value) => {
        list.push(value)
        if(list.length === arr.length) {
          resolve(list)
        }
      }, (err)=> {
        reject(err)
      })
    })
  })
}

Originally posted by @learnRy in #23 (comment)