re: ES6 Arrow Functions Cheatsheet VIEW POST

TOP OF THREAD FULL DISCUSSION
re: While I love the arrow function syntax of ES6, I feel like the implicit returns could be a bit problematic. I personally feel in large projects we ...
 

Like a lots of things in JS, you can screw yourself if you're not careful with the flexible syntaxe.

ESlint (with airBnB rules) can help a lot with this. As you said, there's two (maybe three) ways to use arrow-functions. Here's the two syntaxes I enforce to myself.

1 Simple one-liner:

this.children.forEach(child => child.remove()); // Without implicit return
const translated = points.map(point => point.add(x, y)); // With implicit return

1.1 Object return:

const options = values.map(value => ({
  value: value,
  size: value.length,
}));

2 Multi-line operation:

object.data.forEach((data) => {
  test(data.value);
  test(data.size);
});
code of conduct - report abuse