Add Support for Assigning Multiple Object Properties at Once

It would be useful to have a concise syntax for assigning the same value to multiple object properties.

Current syntax:

coordsOnClick.x = coordsOnClick.y = 0;

Proposed syntax:

coordsOnClick.{ x, y } = 0;

This could improve readability and reduce repetitive code when updating multiple properties with the same value.

The language is 99.995% unlikely to adopt this change.

You could make a function though:

let resetCoords = (coords) => {
  coords.x = coords.y = 0;
}

The optimizing compiler will usually "inline" this function where it is used so that you won't even be paying for the overhead of making the function call.

1 Like