fail-fast object destructuring (don't add more slop to sloppy mode)

Brendan Eich brendan at mozilla.com
Sat Jan 5 11:59:15 PST 2013


Kevin Smith wrote:
> Using suffix-? on the expression side is not backward compatible for 
> the ASI reasons already mentioned:
>
>     a.b?
>     c:
>     d;

I raised this problem-case, so I want to point out that we could take 
other courses:

* Reckon that labels are rare and this won't bite, so let it stand, just as

a = b
(c)

is a hazard today -- and one that bites much more.

* Don't allow suffix-? to be followed by a newline.

> So we're down to two possibilities:
>
> 1) Expression: prefix-?, Pattern: suffix-?
> 2) Expression: prefix-? Pattern: prefix-?
>
> Consistency would seem to dictate (1).
>
>     { p: { ?q: v } } = o;
>     v = o.p.?q;

You must have meant (2).

Apart from deviating from the cowpath (CoffeeScript), prefix-? is 
equivalent to suffix-? as I argued in reply to Herby. We'd want to support

   let ?{p: v} = o;
   let v = ?o.p;

to handle the case of undefined or null 'o', of course, in which case v 
would be initialized to undefined.

Stopping here to make sure we are in sync.

/be


More information about the es-discuss mailing list