手写Promise.all()
时间: 2023-12-07 13:39:11 浏览: 89
手写promise,实现
下面是手写Promise.all()的实现代码:
```javascript
function promiseAll(promises) {
return new Promise((resolve, reject) => {
let result = [];
let count = 0;
for (let i = 0; i < promises.length; i++) {
Promise.resolve(promises[i]).then(res => {
result[i] = res; count++;
if (count === promises.length) {
resolve(result);
}
}).catch(err => {
reject(err);
});
}
});
}
```
阅读全文