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

Brendan Eich brendan at
Wed Jan 2 13:17:43 PST 2013

Kevin Smith wrote:
>     You're right, this implies destructuring binding forms behave in a
>     way that I flagged as possibly not wanted:
>       let {p?: {q: r}} = o;
>     would bind r to undefined for any o that doesn't have a p or that
>     does but o.p doesn't have a q. 
> So as Nil cascades downward, it essentially converts the whole subtree 
> to a "deeply" irrefutable pattern.

I would rather recast this into the expression language from the pattern 
language before invoking most-holy Nil :-P.

   console.log({p: {q: 42}}.p?.q);

logs 42, while

   console.log({p: {s: 42}}.p?.q);

would log undefined which could be nil in disguise, or not (see my 
previous post to this one).

Destructuring with the opt-in irrefutable syntax, suffix-? is my 
preference, does not seem to me to involve Nil in its explanation or 

Sorry to be a stickler. I do not want to couple destructuring to exposed 

>     On second look this is not as bad as I thought. It would be bad if
>     r were not bound (so an outer r could become visible) depending on
>     o's dynamics. That seems right out!
> Yes, let's lobbest thy holy hand grenade at that one.



More information about the es-discuss mailing list