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

Brendan Eich brendan at mozilla.com
Wed Jan 2 07:57:33 PST 2013


Herby Vojčík wrote:
> I advised adding Null Pattern Object into language in the 
> aforementioned thread; and use foo? as `foo == null ? 
> NullPatternObject : foo`.
>
> So you can do `r = o?.p.q`; and it does not fail.

Separate topic, and we considered it as an alternative to CoffeeScript's 
non-compositional rewrite-based semantics at the September TC39 meeting, 
but did not proceed. Thanks for the reminder, I will update 
http://wiki.ecmascript.org/doku.php?id=strawman:existential_operator.

> With such construct you could do
>   let {p: {q: r}} = deep_o?; 

This does not address the problem for destructuring. It's true a Nil 
object (as Brandon Benvie prototyped: 
https://github.com/Benvie/nil/blob/master/nil.js) can be deeply 
destructured. But there is no refutable match future. We need an 
exception on missing property, not a magic get/set-sink object.

The suffix-? syntax in expressions is problematic in combination with 
missing semicolons. You get another case where programmers expect ASI 
but there's no error to correct:

   x = y?
   z:w

where z is label and w is a statement that can syntactically (if not 
sensibly) be labeled.

/be


More information about the es-discuss mailing list