Allen reminded me to mention that destructuring assignment, as opposed to binding, allows arbitrary LeftHandSideExpression in the patterns, as opposed to Identifiers. If someone wants to use that extravagence in an object pattern destructuring assignment, they can put parens around the whole thing.

/be

Brendan Eich <mailto:[email protected]>
September 17, 2013 10:27 AM

That's it. Lars Hansen originated destructuring for ES4 and implemented array patterns in Futhark (Opera's engine of the time), but not object patterns. His first proposal used

&{a: x, b: y} = foo

for just the reason you cite, but no one was keen on the ASI hazard (previous line must end with a semicolon). We cut the & pretty soon in ES4's evolution.

I say use var/let/const, it's better style; or else suffer a parentheses tax. This is pretty much a non-issue in practice, AFAICT.

/be
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Nathan Wall <mailto:[email protected]>
September 17, 2013 10:06 AM
I'm wondering what the best syntax is for object destructuring outside of a var declaration. For instance, the following works in Firefox Nightly and Traceur:

    var { a, b } = foo;

but the following doesn't:

    var a, b;
    { a, b } = foo;

I presume this is because in the second case the { a, b } is a block.

However, the following does work:

    var a, b;
    ({ a, b }) = foo;

Is the above what people are expected to use (when they need to use destructuring outside of a var/let declaration or function arguments), or is there another form available?

Thanks,
Nathan
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to