fail-fast object destructuring

Andreas Rossberg rossberg at
Wed Jul 4 06:46:14 PDT 2012

On 2 July 2012 20:17, Brendan Eich <brendan at> wrote:

> Andreas Rossberg wrote:
>> Hm, I don't think I used it differently. Or did I misunderstand what
>> Claus meant?
>> /Andreas
> From Claus's 26-June message:
>  3) Again we have a internal consistency issue:
>>   let myFoo = {a:0,b:1}.foo;
>> vs
>>   let {foo: myFoo} = {a:0,b:1};
>> why should one work and the other fail?  The general rule of JS is that
>> accessing a missing property returns undefined.
> Ultimately, I'd like to have both:
> - irrefutable matching:
>    here, the two phrases above are equivalent, as in the
>    destructuring proposal
> --- end citation ---
> Is the equivalence between those two let declarations the same as one-case
> pattern matching? One-case matching in many languages with "pattern
> matching" will fail on mismatch, whereas destructuring that preserves the
> above equivalence must succeed and initialize myFoo to undefined.
> Should we call the fail (throw) vs. succeed distinction something other
> than refutable vs. irrefutable?

Hm, I suppose I'm a little confused now what terminology we are actually
trying to resolve. AFAICT, the meaning of refutable vs irrefutable is
independent of any equivalences you may or may not want to hold.
(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.)

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

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

IMHO this equivalence would be much more important, because it is necessary
for giving a uniform meaning to patterns per se.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list