Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it necessary to convert arguments to Array before calling apply?

Are there any browser restrictions or any other issues that prevents me from doing:

fn.apply(this, arguments);

versus:

fn.apply(this, Array.prototype.slice.call(arguments));

I know that apply takes a "true" Array as second argument, but passing an arguments collection seems to work just as good. or...?

like image 809
David Hellsing Avatar asked Oct 06 '22 11:10

David Hellsing


1 Answers

According to the MDN, it "Calls a function with a given this value and arguments provided as an array (or an array like object)". Given that arguments is an array-like object, there shouldn't be any restriction on using it.

In fact, the description explicitly says arguments is a valid parameter.

like image 117
saml Avatar answered Oct 10 '22 03:10

saml