5 ms·
I thought arrow functions were just designed to reduce verbosity and make code easier to read. Is there another reason?
by takinola 3y ago
I thought arrow functions were just designed to reduce verbosity and make code easier to read. Is there another reason?
- AA-BA-94-2A-56 3y agoI could be wrong, but don’t JavaScript’s closures rely on arrow syntax?
- takinola 3y agoI'm pretty sure closures are available to any function regardless of how they are defined. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures https://developer.mozilla.org/en-US/docs/Web/JavaScript/Clos...
- irrational 3y agoNo, anything you can do with arrow functions can be done without them. Arrow functions are just a simpler way of writing code. For example, you can control "this" in non-arrow functions using tools like call, apply, and bind. It is just more verbose.
- seangrogg 3y agoYes, arrow functions have a different (and more intuitive) lexical `this` than their more verbose counterpart. It is subtly more than just a syntax sugar.
- takinola 3y agoHa, I finally figured out how "this" works and then they changed it with arrow functions.