Skip to content

【Promise第25题】下面代码的输出是什么?

js

function runAsync (x) { const p = new Promise(r => setTimeout(() => r(x, console.log(x)), 1000)) return p } Promise.all([runAsync(1), runAsync(2), runAsync(3)]) .then(res => console.log(res))


## 参考答案:

## 解析

.all()的作用是接收一组异步任务,然后并行执行异步任务,并且在所有异步操作执行完后才执行回调。

## 答案

1 2 3 [1, 2, 3]