fail-fast object destructuring

Brendan Eich brendan at
Wed Jul 4 08:01:43 PDT 2012

Andreas Rossberg wrote:
> (Refutable: a pattern that may fail to match, raising an error; 
> irrefutable: a pattern that is matched by anything, but potentially by 
> binding nullish values to pattern variables.)

(That is indeed the definition we all share -- thanks.)

> The current draft tries to make all/most destructuring patterns 
> irrefutable. The above equivalence is the motivation (though not the 
> "definition" of irrefutable).

Sure (I didn't write "definition"). That motivation comes from JS as it 
is today, without pattern matching.

> I understand that motivation, but was trying to point out that it is 
> merely one under several (conflicting) potential equivalences to 
> consider. For example, in languages with pattern matching I usually have
>   let pat = exp; stats
>   ~=
>   match (exp) { case pat: stats }
> (Assuming a match without a default throws, otherwise add an explicit 
> error default.)
> IMHO this equivalence would be much more important, because it is 
> necessary for giving a uniform meaning to patterns per se.

If only JS had pattern matching!

We may add pattern matching, but does that future possibility make the 
equivalence you cite more important than the one JS programmers might 
expect today?

We could try to have our cake and eat it, by extending the pattern 
language with prefix-! or prefix-?. Which prefix depends on the choice 
of default behavior, based on ranking of the two equivalences. Whatever 
that ranking, does this make sense so far?


More information about the es-discuss mailing list