function foo(x) { console.log(arguments) } //foo(1) prints [1]
but
var bar = x => console.log(arguments)
gives the following error when invoked in the same way:
Uncaught ReferenceError: arguments is not defined
Arrow functions do not have an arguments binding. However, they have access to the arguments object of the closest non-arrow parent function. Named and rest parameters are heavily relied upon to capture the arguments passed to arrow functions.
Arrow functions don't have their own arguments object. Arrow functions do not expose an arguments object to their code: arguments. length , arguments[0] , arguments[1] , and so forth do not refer to the arguments provided to the arrow function when called.
An Arrow function should not be used as methods. An arrow function can not be used as constructors. An arrow function can not use yield within its body. Arrow function cannot be suitable for call apply and bind methods.
The arrow function, on the opposite, doesn't define arguments (but you can easily access the arrow function arguments using a rest parameter ... args ). If the arrow function has one expression, then the expression is returned implicitly, even without using the return keyword.
Arrow functions don't have this since the arguments
array-like object was a workaround to begin with, which ES6 has solved with a rest
parameter:
var bar = (...arguments) => console.log(arguments);
arguments
is by no means reserved here but just chosen. You can call it whatever you'd like and it can be combined with normal parameters:
var test = (one, two, ...rest) => [one, two, rest];
You can even go the other way, illustrated by this fancy apply:
var fapply = (fun, args) => fun(...args);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With