fail-fast object destructuring

Russell Leggett russell.leggett at gmail.com
Wed Jul 11 08:22:05 PDT 2012


On Wed, Jul 11, 2012 at 7:16 AM, Andreas Rossberg <rossberg at google.com>wrote:

> On 10 July 2012 10:47, Russell Leggett <russell.leggett at gmail.com> wrote:
>
>> Another thing that I was also thinking is that it might look a little
>> nicer if the ? was a post-fix instead of a pre-fix.
>>
>>     let {first, last, company?} = contact;
>>
>> I might be missing why this wouldn't work out, but it aesthetically just
>> looks right to me. It looks like the regex operator, and is also obviously
>> the position it would be in english.
>>
>
> Even parsing issues aside, I don't like postfix better. It is easier to
> miss, especially if ? was possible on patterns, not just properties.
> Consider:
>
>   let {the, that: {x, y}, those, theirs: {what, why}, thus}? =
> callSomething()
>
> How easy is it to miss the final '?' when looking for the binding of 'x'?
>
> But even on longish property names it can be a tad too easy to overlook:
>
>   let {what, why, whatTheHeckIsGoingOn?} = callSomething()
>

I know what you're saying, but I think it is widely used as postfix. People
are used to it. And it reads fine to me here:

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

 - Russ

>
> /Andreas
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120711/9634738a/attachment-0001.html>


More information about the es-discuss mailing list