3 ms·
I recently witnessed the absurdity of arrow functions NOT returning implicitly if you put the function body in {}. It's a shit show.
by serpix 11y ago
I recently witnessed the absurdity of arrow functions NOT returning implicitly if you put the function body in {}. It's a shit show.
- rimunroe 11y agoThat actually is one of my favorite things about arrow functions next to the no-changing-this aspect. I find CoffeeScript's optional return statement really awkward to read for anything that isn't a one-liner. I don't want to have side-effectful functions return values, and dropping bare statements in in order to accomplish that seems extra noisy.
- btdiehr 11y agoIf you want to return an object literal just do this, `(text) => ({ label: text })` In my opinion the arrow function has great syntax. Rest assured, no matter what the syntax was chosen to be, there would be an extremely vocal group of people who hate it (such as yourself).
- rhinoceraptor 11y agoThat's part of the spec, they're really meant for doing functional style, one liner type of things, like [1, 2, 3, 4].map(x => x + 1) You should probably avoid using them for other applications, particularly if you're using a library that uses prototypes because it won't work.
- douche 11y agoIf that's what they are for, why call them "arrow functions", and not lambdas like everybody else does?
- rhinoceraptor 11y agoJavascript already had lambdas/anonymous functions since the beginning.
- TheCoelacanth 11y agoTo distinguish from javascript's other longer way of writing the same thing: [1, 2, 3, 4].map(function (x) { return x + 1; })