tc39/proposal-object-rest-spread

Using spread in computed property names

kevinlaw91 opened this issue · 2 comments

Just came across this idea and it can be useful. Any thoughts?

let arr = ['foo1', 'foo2', 'foo3'];
let sharedData = "sameValue";

let payload = {
  [..arr]: sharedData
}

This is interesting, but orthogonal to this proposal.

This using array destructuring to do computed property assignment on objects. First, there would need to be another proposal for computed assignment from arrays. Something like { ['foo1', 'foo2', 'foo3']: sharedData }, from there you could propose { [...arr]: sharedData }. In any case it seems unrelated to this proposal.

Good point! Closing this as this is not really fit into the proposal. But I really hope that this idea can be implemented in future if someone sees the potential. Cheers!