ES6 supports computed properties.
// code from my original question now works in ES6 ! let b = "foo"; let a = { [b]: "bar" }; a.foo; //=> "bar"
Any expression can be used in [] to specify a property name
let a = { [(xs => xs.join(''))(['f','o','o'])]: 'bar' }; a.foo;
If you need to rely on this behavior in the ES5 world, you can rely on the very capable babel.js to override your ES6 code with an ES5-compatible code.
naomik
source share