小编RCh*_*aud的帖子

为什么直接将Promise.all传递给.then函数会抛出错误?

我想直接传递Promise.all.then像这样的函数:

const test = [
    Promise.resolve(),
    Promise.resolve(),
    Promise.resolve(),
    Promise.resolve()
];

Promise.resolve(test) // It's supposed to be an AJAX call
.then(Promise.all) // Get an array of promises
.then(console.log('End');
Run Code Online (Sandbox Code Playgroud)

但是这段代码会引发错误Uncaught (in promise) TypeError: Promise.all called on non-object.

当我删除速记语法时,它的工作原理如下:

Promise.resolve(test)
.then(queries => Promise.all(queries))
.then(console.log('End'));
Run Code Online (Sandbox Code Playgroud)

那么为什么一个Promise.all直接传递给一个.then错误?(为什么一个console.log工作正常?)

javascript

7
推荐指数
1
解决办法
1131
查看次数

标签 统计

javascript ×1