When need to use arrow function? | Sololearn: Learn to code for FREE!


When need to use arrow function?

arrow function in es6

11/5/2016 6:15:23 AM

Вадим Глушков

2 Answers

New Answer


Much of the time, you don't need to use it, it is primarily there for convenience in throwaway callback functions and reduces boilerplate noise in your code. For example, `[1,2,3].map(v => v * 2)` instead of `[1,2,3].map(function(v) { return v * 2; })`. Importantly, it also fixes an issue with `this`; because the scoping works differently, it allows you to use `this` from the outer scope, which means you don't ever have to use `var self = this;` or var myTimeout = function(){ blah blah blah }.bind(this);` to hold onto the value. That's the most important practical reason.


Daniel! Thank you. Very excellent answer.