javascript - Spread operator ES5 equivalent - Stack Overflow

Below is the code I am trying to convert to ES5 for IE patibility.$.when(...requests).then(function(..

Below is the code I am trying to convert to ES5 for IE patibility.

$.when(...requests).then(function(...responses) {
   // More code goes here
}

So far I could convert it to the below and it works well, but I still couldn't replace the then part.

$.when.apply(null, requests).then(function(...responses) {
   // More code goes here
}

Any suggestion would be really appreciated.

Below is the code I am trying to convert to ES5 for IE patibility.

$.when(...requests).then(function(...responses) {
   // More code goes here
}

So far I could convert it to the below and it works well, but I still couldn't replace the then part.

$.when.apply(null, requests).then(function(...responses) {
   // More code goes here
}

Any suggestion would be really appreciated.

Share Improve this question asked May 31, 2021 at 15:17 Parag KadamParag Kadam 3,8805 gold badges27 silver badges57 bronze badges 2
  • 1 Why not transpile the code? – VLAZ Commented May 31, 2021 at 15:28
  • 1 Also, you seem to only be asking about rest parameter syntax: function(...responses). Only $.when(...requests) is using spread. – VLAZ Commented May 31, 2021 at 15:30
Add a ment  | 

1 Answer 1

Reset to default 4

There is arguments:

$.when.apply(null, requests).then(function() {
   var responses = [].concat.apply([], arguments); // Get a standard array from arguments object
   // More code goes here
}

As a disclaimer I quote MDN on the use of arguments:

If you're writing ES6 patible code, then rest parameters should be preferred.

So when you don't have ES6 support (which seems to be your case), then using arguments is fine, but otherwise you should use the spread syntax in the function parameter list.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745550232a4632542.html

相关推荐

  • javascript - Spread operator ES5 equivalent - Stack Overflow

    Below is the code I am trying to convert to ES5 for IE patibility.$.when(...requests).then(function(..

    18小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信