A few of my favorite ES6 features that help me write less boilerplate code.
Property shortcuts
1 | const name = 'joe' |
1 | // es6 |
Read http://es6-features.org/#PropertyShorthand
Destructuring
1 | // es5 |
1 | // es6 |
Read http://es6-features.org/#ObjectMatchingShorthandNotation and Parameter destructuring.
Default values
1 | // es5 |
1 | // es6 |
Read http://es6-features.org/#DefaultParameterValues
Separate arguments
1 | // ES5: need all arguments after "y" |
We could use a utility library
1 | const _ = require('lodash') |
But the best is ES6 "rest" operator
1 | // ES6 |
Read http://es6-features.org/#RestParameter
Computed keys
1 | // es5 |
1 | // es6 |
Read http://es6-features.org/#ComputedPropertyNames
Arrow functions
1 | numbers.map(function (v) { return v + 1 }) |
For clarity I prefer Ramda functions
1 | var R = require('ramda') |
But arrow functions make tiny "curried" functions so simple, especially for making callbacks
1 | const foo = options => value => { |