Obj2.{ x, y } = Obj1 Destructuring Assignment

Allow assignment of properties from one object to another using destructuring / structuring.


  let a = { x:1, y:2 };

  let b = { z:3 };

  b.{ x, y } = a;
  //b is now { z:3, x:1, y:2 }

Currently, .{ is a syntax error, so this syntax is unambiguous.
And its meaning is so intuitive, that this post does not even have any more explaining to do. :-|

4 Likes

I've seen this in at least one of the few pick/omit-like proposals floating around. This one I dug up real quick includes it: GitHub - jfet97/tc39-proposal-dotstructuring: Proposal: Object dotstructuring

2 Likes

I LOVE THIS. Looks like a shortcut to {x: b.x, y: b.y} = a; and this is just great! I would actually make big use of this

1 Like

It's beautiful. This should totally be a thing. I've often wished this was possible.