实现一个Promise all
------------恢复内容开始------------
function myPromiseAll(list) { return new Promise((res) => { let promiseAllArr = []; let num = 0; list.forEach((item,index) => { promiseAllArr[index] = item; if (num === list.length){ res(); } }) }) } const a1 = new Promise((resolve,reject) => { setTimeout(()=>{ console.log('a1') }, 2000) }) const a2 = new Promise((resolve,reject) => { setTimeout(()=>{ console.log('a2') }, 5000) }) myPromiseAll([a1,a2]);
------------恢复内容结束------------