+
95
-

如何手写一个 Promise.all?

如何手写一个 Promise.all?


网友回复

+
15
-
// 自定义 Promise.all 的实现
function myPromiseAll(promises) {
  return new Promise((resolve, reject) => {
    let results = [];
    let count = 0;

    for (let i = 0; i < promises.length; i++) {
      promises[i].then((result) => {
        results[i] = result;
        count++;

        if (count === promises.length) {
          resolve(results);
      ...

点击查看剩余70%

我知道答案,我要回答