2 ms·
> Relative to the other kind of function that is written like function (x) { return x * 2 }, arrow functions don't define this or arguments in their bodies, ins
by moron4hire 11y ago
> Relative to the other kind of function that is written like function (x) { return x * 2 }, arrow functions don't define this or arguments in their bodies, instead capturing these values from the environment.
In the case of `this`, I can see why they did that: it is the right semantics and all of JavaScript should be this way. But I really think creating two different behaviors for what should all just be syntactic sugar around the same, ol' function values is long-term going to reveal itself as a mistake.
But that's just `this`. I can't for the life of me imagine why they also did this for `arguments`.
- ubertaco 11y agoI think that was largely to make it easier to deal with arrow functions in higher-order functions, though the only case I can see for "arguments" anymore is for varargs, and those are covered with the rest operator, so I'm not sure why the distinction is made.
- moron4hire 11y agook, that makes sense. Yes, `arguments` is a shitty replacement for real varargs.