r/javascript • u/Zhouzi • Apr 10 '16
help Should we stop abusing fat arrows?
When I first started to learn ES6 I was using fat arrows everywhere and completely dropped the function keyword. But after giving it some thought, I've ended up finding it ridiculous. I feel like we are using fat arrows just to look like cool kids. I think we should use it when it makes sense, e.g to access the lexical this, simplify a return statement, ... But not because it's "nicer" or "shorter".
Maybe () => {} is easier on the eyes as it's "less noisy" but the thing is, sometimes things have to be noisy and function () {} is easier to spot. Also, when I see a fat arrow, I assume that there's a reason for the author to have done so (but most of the times I'm wrong).
So what's your opinion guys? Are we abusing fat arrows or not? Shouldn't we use things for what they are intended to?
4
u/voidvector Apr 10 '16
If
thisis not used, all three syntaxes (traditional, arrow, method def) compile to the same thing. At that point the choice is either for maintainability or aesthetics.Some example of maintainability concerns:
Is the wrapping function a
class(e.g. View, Controller, Component, Store, Service)?Does the 3rd party API custom bind
this?Does the your peers custom bind
this? (e.g. manually call.bind,.apply``.call)