fail-fast object destructuring

Brendan Eich brendan at mozilla.org
Mon Jul 2 11:17:13 PDT 2012


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?

/be




More information about the es-discuss mailing list