因此 Promise.all 将数组作为值传递到函数中,我更希望它将数组值作为参数传递。
假设我有这个功能:
function printData(a,b,c){
console.log(a,b,c)
}
我想
Promise.all([1,2,3]).then(printData)
>> [1,2,3] undefined undefined
改为打印此内容
>> 1 2 3
有没有更好的方法来做到这一点:
Promise.all([1,2,3,4]).then(function(values){printData.apply(null, values)})
使用扩展运算符?
我也尝试过
Promise.all([1,2,3]).then(printData.apply)
但它返回一个错误