Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I didn't know you could do this!

      // good
      const obj = {
        id: 5,
        name: 'San Francisco',
        [getKey('enabled')]: true,
      };


Next 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.


Yep, computed property names is another ES6 feature




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: