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
1 Answer
Reset to default 4There 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
评论列表(0条)