Extended dot notation (pick notation) proposal

Bergi a.d.bergi at web.de
Thu Sep 22 18:16:21 UTC 2016

Bob Myers wrote:
> This is a creative idea. I'd rather see it in the language than not. But
> still half a loaf.

Yeah, it's not the whole thing, but I believe it's something the TC 
could agree on before moving further.

> Minor nit: I don't see how this is a "simplification in object
> destructuring". It has nothing to do with destructuring, right?

For consistency and ease of understanding I would apply the same pattern 
for destructuring cases, i.e.
({o1.x, o1[y]} = o2);
desugars to
({x: o1.x, [y]: o1[y]} = o2); // but `y` being evaluated only once

This would help a great deal where the object on which the properties 
should be assigned already exists, e.g. in a constructor:
constructor(options) {
     ({this.propA, this.propB, this.optOne} = options);
to provide some kind of "selective `Object.assign`".

> It's a bit sad that I don't see how to get to renaming and defaults with
> this syntax.

Renaming has always been part of the language:
o2 = {y: o1.x} // o2.y = o1.x
({y: o2.z} = o1); // o2.z = o1.y
and with destructuring we'd also get defaults.

- Bergi

More information about the es-discuss mailing list