Extended object literal property value shorthand

# Bob Myers (10 years ago)

Thanks Rick. Yes, I was hoping to make the following work:

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

This is not destructuring, it's an extension to object literal property value shorthand. The idea is to derive the desired property name a from x.a. However, it could be difficult to define when and how a property name could be derived from various types of member expressions.

Here is an alternative, admittedly not too pretty, but perhaps easier to define and/or implement. The idea is to generalize the permissible properties for which values can be omitted/inferred, and also allow LHS destructuring-type syntax, so:

x = {a: 1}; y = {b: 2};

If I want to extract the two values using destructuring assignment today we can do:

var { x: {a}, y: {b} } = { x, y }; // a=1, b=2

Consider using the LHS destructuring syntax in the above as an expanded shorthand property:

z = { { x: {a}, y: {b} } } // // {a: 1, b: 2}

This kind of re-use of destructuring syntax would permit "renaming" "on-the-fly":

z = { { x: {a: A}, y: {b: B} } } // // {A: 1, B: 2}

Or pulling things from arrays:

q = [1, 2, 3]; z = { { x: a, } }

erty" would be conceptually destructured into

{ x: {a}, y: {b} }

z = { x: {a}, y:

# Bob Myers (10 years ago)

send too soon, please ignore.