2 ms·
I didn't know you could do this! // good const obj = { id: 5, name: 'San Francisco', [getKey('enabled')]: true, };
by tehwebguy 11y ago
I didn't know you could do this!
// good
const obj = {
id: 5,
name: 'San Francisco',
[getKey('enabled')]: true,
};
- natrius 11y agoNext to arrow functions and optional arguments, better object syntax is one of the big reasons you should be using Babel today. You know how sometimes you need to precalculate values that are going to be returned in an object, so at the end of the function, you return something like this? return { foo: foo, bar: bar, baz: baz }; You don't have to do that in ES6. return {foo, bar, baz}; Keys without values use variables with the same name as their values.
- taternuts 11y agoYep, computed property names is another ES6 feature