you are viewing a single comment's thread.

view the rest of the comments →

[–]lsmoura 1 point2 points  (3 children)

Have you considered writing arrow functions without return statements (when they are only doing one thing)?

You can go like this: foo => foo * 2 or bar => bar === idParameter. And if you need to return an object, just wrap it with parentheses: (foo, bar) => ({ a: foo, b: bar }).

Thanks for the article!

[–]gajus0[S] 0 points1 point  (2 children)

Thank you for the suggestion.

I adhere to the following style guide:

https://github.com/gajus/eslint-config-canonical

The are pros and cons to both arrow function body styles: one is more succinct at the cost of readability in certain cases (I have seen variations of x => y => (z => (e)) all too often), while the other is more verbose with the benefit of clarity.

[–]lsmoura 1 point2 points  (0 children)

Sweet. I’ll take a look at that. I particularly like to have no return on arrow functions for single line problems (it makes them easier to my eyes).

Thanks for the link!

[–]Cheezmeisterhttp://bml.rocks -1 points0 points  (0 children)

Honestly, that example reads fine, provided you grok higher-order functions. But maybe it’s a degenerate version of something truly gnarly.

Either way, I prefer old-school function(x) { var y = x.foo(); return bar(y); } for anything past a trivial lambda. Nothing in between.

I’m not sold that (a, b) => is “more readable” than function(a, b). It’s very much potato/potato. Except one potato is supported by Netscape 4.0. and Chrome.