我想直接传递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 ×1