destructuring: as patterns?

Brendan Eich brendan at mozilla.org
Fri Apr 20 16:08:43 PDT 2012


Allen Wirfs-Brock wrote:
> What I'm really pushing at here is the throw. Let's are  used for 
> establishing and initializing bindings.  From a binding perspective:
>
>     let x ;
> and
>     let {x} = {};
>
> are almost exactly the same thing.  They both establish a hoisted 
> uninitialized lexical binding for x.  They both delimit the end of the 
> TDZ for x. They both supply undefined as the initialization value of 
> x. Why should the second form throw when the first doesn't?

That is a good question.

Lars Hansen spec'ed destructuring for ES4 based on the array-pattern 
destructuring he had implemented in Opera, which does not throw. It 
plucks out undefined, of course, and trying to destructure deeper from 
undefined will throw. This is what we implemented in JS1.7+ in 
SpiderMonkey and Rhino.

Andreas and Dave can make the throwing case better than I, so I will tag 
one or both of them in.

/be


More information about the es-discuss mailing list