Stage 4
Classification: Syntactic Change Semantic Change
Human Validated: KW
Title: Rest/Spread Properties
Authors: Sebastian Markbåge
Champions: Sebastian Markbåge
Last Presented: January 2018
Stage Upgrades:
Stage 1: 2014-10-29
Stage 2: 2015-08-25
Stage 2.7: NA
Stage 3: 2016-09-29
Stage 4: 2018-02-13
Last Commit: 2022-01-24
Topics: objects iterators others
Keywords: property copy iterable rest_properties spread_properties destructuring
GitHub Link: https://github.com/tc39/proposal-object-rest-spread
GitHub Note Link: https://github.com/tc39/notes/blob/HEAD/meetings/2018-01/jan-23.md#restspread-properties-for-stage-4
Proposal Description:
Object Rest/Spread Properties for ECMAScript
ECMAScript 6 introduces rest elements for array destructuring assignment and spread elements for array literals.
This proposal introduces analogous rest properties for object destructuring assignment and spread properties for object literals.
Specification
Rest Properties
Rest properties collect the remaining own enumerable property keys that are not already picked off by the destructuring pattern. Those keys and their values are copied onto a new object.
let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
x; // 1
y; // 2
z; // { a: 3, b: 4 }
Spread Properties
Spread properties in object initializers copies own enumerable properties from a provided object onto the newly created object.
let n = { x, y, ...z };
n; // { x: 1, y: 2, a: 3, b: 4 }
Transpilers
Status of this Proposal
It is a Stage 4 proposal for ECMAScript.
Known Issues
This proposal only iterates over own properties. See why this matters.