Destructuring assignment

Brendan Eich brendan at
Thu Aug 21 23:27:16 PDT 2008

On Aug 21, 2008, at 10:02 PM, David-Sarah Hopwood wrote:

> There is a comment at the end of the discussion page saying:
> # We decided against object property shorthand in destructuring  
> such as:
> #
> # { x, y, z } = { x: 1, y: 2, z: 3 }
> #
> # This would be nice and concise, but possibly so terse as to be  
> confusing.
> # Part of the justification of destructuring is that its syntax  
> exactly
> # mimics that of structuring.
> # — Dave Herman 2006/10/20 12:24

That's out of date. Writing object destructuring binding patterns  
often since then, in building the ES4 RI with its self-hosted built- 
ins, and the ESC self-hosted compiler on Tamarin, led us to the  
strong desire for the short-hand. The rest of the RI was in SML,  
which has the same sort of destructuring pattern, which closed the deal.

Sorry no one updated the wiki -- clearly, you have a point in noting  
the lack of a community to tend pages.

> and the syntax on the proposal page does not include this shorthand.

In JS1.8 in Firefox 3.

> I don't have a particularly strong opinion on this (because it has
> no semantic implications and the desugaring is trivial), but is the
> shorthand proposed for ES-Harmony and/or ES3.1, or not?

ES3.1 is out in draft spec form, was originally hoped to be done at  
end of this year, should be done by next spring with interoperable  
implementations based on its all-but-done drafts, and is not  
including anything other than the Array extras and property getters  
and setters from JS1.x.

So, Harmony.

> assuming that is is possible to mix the shorthand and longhand forms
> for different fields.

js> function bar() { return {p:42, q:"hi"} }
js> var {p, q:r} = bar()
js> p
js> r


More information about the Es-discuss mailing list