Errors in syntax for array destructuring?

Dominic Cooney dominicc at
Thu Oct 14 23:47:19 PDT 2010

On the harmony:destructuring page
<> it
specifies this syntax for patterns:

Pattern ::= "{" (Field ("," Field)*)* "}"
          | "[" ((Pattern | LValue)? ",")* "]"
Field   ::= Identifier (":" (Pattern | LValue))?
LValue  ::= <any lvalue expression allowed in a normal assignment expression>

Is it intentional that commas aren't required between fields of an
object pattern, for example, {x y}? That seems concise, but odd.
SpiderMonkey doesn't support this syntax.

Likewise, why aren't trailing commas permitted in object destructuring
as they are in object literals? SpiderMonkey accepts trailing commas.

Finally, surely trailing commas aren't *required* in array
destructuring? The second alternative seems to indicate that they are.
SpiderMonkey doesn't require trailing commas.

Shouldn't the syntax be something like:

Pattern ::= "{" (Field ("," Field)* ","?)? "}"
        | "[" (ArrayField ("," ArrayField)*)? "]"

ArrayField ::= (Pattern | LValue)?

(Field as before)



More information about the es-discuss mailing list