An array destructing specification choice

Allen Wirfs-Brock allen at wirfs-brock.com
Mon Nov 7 08:07:50 PST 2011


On Nov 7, 2011, at 2:18 AM, Andreas Rossberg wrote:

> On 5 November 2011 17:44, Brendan Eich <brendan at mozilla.com> wrote:
>> Destructuring is "irrefutable" in that it desugars to assignments from properties of the RHS. It is not typed; it is not refutable
> 
> I don't think that's true, at least not in the usual sense of
> "irrefutable pattern". Because you can write
> 
>  let {x} = 666
> 
> which will be refuted, by raising a TypeError.

No,

It does ToObject(666) and then looks for the "x" property of the resulting wrapper object.  Assume it does find one (it could, for example because Number.prototype.x = 42, for example) it assigns the value to x.  If it doesn't find the property it assigns undefined.  
For 
 let {x=5} = 666;

It would assign 5 to x if the "x" property of the wrapper was not found,

> 
> Of course, the real question is, what does this do:
> 
>  let {} = 666

It does ToObject(666)



> 
> /Andreas
> 



More information about the es-discuss mailing list