Historically, we had to do:
var args = Array.prototype.slice.call(arguments)
fn.apply(this, args);
to grab actual function call arguments and pass them to Function.prototype.apply. However, since some time, I can see that arguments object does have slice method available, hence above snippet is not required anymore.
The question is - when did it change, what was it, a specification update?
edit: I was unclear above... I mean that fn.apply(this, arguments) does work (I checked in latest chrome and firefox):
function add(a,b){
return a + b;
}
function whatever(){
return add.apply(null, arguments)
}
whatever(2,3) // 5
in other words, arguments can be now used within apply directly. Some time ago, it didn't work, it had to be passed to Array.prototype.slice.apply as above.
Array.from(arguments)with new ES2016 :)arguments.slice()for me in Firefox.argumentsis an array. It's just that those methods work for array-like objects: objects with a.lengthproperty and properties with integer names.