简体   繁体   English

Promise.all 是在什么规范中引入的?

[英]In what specification was Promise.all introduced?

I'm trying to document the solution of a common interview question and how the solution has changed with language updates.我正在尝试记录一个常见面试问题的解决方案以及该解决方案如何随着语言更新而改变。

For example, const & let were introduced in ES2015 making the problem easier to solve.例如,在 ES2015 中引入了 const & let 使问题更容易解决。

At what specification year was Promise.all introduced? Promise.all 是在哪一年推出的?

Related Code相关代码

// solution using promises
//
function asyncMap(tasks, callback){
  tasks = tasks.map(task => new Promise(task))
  return Promise.all(tasks)
    .then(callback);
}


// solution using let and const introduced in ES2015
// released in 2015 and sometimes referred to as ES6
function asyncMap1(tasks, callback) {
  const results = [];
  let count = 0;
  for (let i = 0; i < tasks.length; i++) {
    tasks[i](function (val) {
      results[i] = val;
      count++;
      if (count === tasks.length) {
        callback(results);
      }
    });
  }
};


// before let was available an IIFE would be needed
//
function asyncMap2(tasks, callback) {
  var results = [];
  var count = 0;
  for (var i = 0; i < tasks.length; i++) {
    (function (i) {
      tasks[i](function (val) {
        results[i] = val;
        count++;
        if (count === tasks.length) {
          callback(results);
        }
      });
    })(i);
  }
};

By looking at the specification document it was at ES2015.通过查看规范文档,它是在 ES2015 中的。 More specific at June 2015.更具体的在 2015 年 6 月。

ECMAScript® 2015 Language Specification ECMAScript® 2015 语言规范

25.4.4.1 Promise.all ( iterable ) 25.4.4.1 Promise.all(可迭代)

If you also want to know if you can use it, just ask it at Can I Use or follow this link .如果您还想知道是否可以使用它,只需在Can I Use 中询问或点击 此链接即可

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM