Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 扩展运算符ES5等效值_Javascript_Jquery_Ecmascript 6 - Fatal编程技术网

Javascript 扩展运算符ES5等效值

Javascript 扩展运算符ES5等效值,javascript,jquery,ecmascript-6,Javascript,Jquery,Ecmascript 6,下面是我试图转换为ES5以实现IE兼容性的代码 $.when(...requests).then(function(...responses) { // More code goes here } 到目前为止,我可以将其转换为下面的格式,并且效果很好,但是我仍然无法替换然后部分 $.when.apply(null, requests).then(function(...responses) { // More code goes here } 任何建议都将不胜感激。这里有: 作为

下面是我试图转换为ES5以实现IE兼容性的代码

$.when(...requests).then(function(...responses) {
   // More code goes here
}
到目前为止,我可以将其转换为下面的格式,并且效果很好,但是我仍然无法替换
然后
部分

$.when.apply(null, requests).then(function(...responses) {
   // More code goes here
}
任何建议都将不胜感激。

这里有:

作为免责声明,我引用了MDN对
参数的使用:

如果您正在编写与ES6兼容的代码,那么应该首选rest参数


因此,当您没有ES6支持时(这似乎是您的情况),那么使用
参数就可以了,但是您应该在函数参数列表中使用扩展语法。

为什么不传输代码?另外,您似乎只询问rest参数语法:
函数(…响应)
。只有
$。当(…请求)
正在使用spread时。感谢您的回答,它似乎与一些调整一起工作->
var responses=[]。concat(参数)[0]。确实如此。我在回答中纠正了这一点。它实际上应该使用
apply
,否则就不会转换为标准数组。但这种转换是可选的。如果不使用数组方法,如
.forEach
,…等,则可以直接使用
responses=arguments
或直接使用
arguments
$.when.apply(null, requests).then(function() {
   var responses = [].concat.apply([], arguments); // Get a standard array from arguments object
   // More code goes here
}