ES2015 Arrow fns do not have the arguments object
const myFn = (/*unknown arity*/) => {
console.log(arguments); //EMPTY ARRAY!
};
function myFn(/*unknown arity*/) {
console.log(arguments); //returns what you expect!
}
My takeaway: only use arrow functions when they’re necessary, which actually isn’t that often! Plain old named JS functions are still powerful and if necessary can still easily be bound with .bind(this).
Related reading: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/arguments
Written on September 29, 2016 by jasonkurian
