fail-fast object destructuring

Russell Leggett russell.leggett at gmail.com
Tue Jul 10 12:31:09 PDT 2012


On Tue, Jul 10, 2012 at 10:40 AM, Brendan Eich <brendan at mozilla.org> wrote:

> Russell Leggett 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.
>>
>
> We have to parse LHS-of-assignment patterns using the Expression cover
> grammar, so this does not work in general due to ?:.
>
> If we parse only in binding contexts (let, const, var on the left, or
> formal params and catch clauses), then we could use a different pattern
> grammar. Worth breaking uniformity with assignment expressions?


Right, I've mostly been thinking about only declaration forms of
assignment, however, thinking about it now, wouldn't it be only a single
token of lookahead to disambiguate? A postfix "optional" operator could
only be followed by , ] } or = (when in the value position) - none of which
would be valid tokens for the ternary operator. If it is on an object
property, it could actually be followed by a :, but that is unambiguous
because it is a property, not an expression.

- Russ


>
>
> /be
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120710/a5774a9c/attachment.html>


More information about the es-discuss mailing list