+ 2
When need to use arrow function?
arrow function in es6
2 ответов
+ 2
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.
+ 1
Daniel! Thank you. Very excellent answer.