Destructuring `undefined` and `null`

Brendan Eich brendan at mozilla.org
Mon Jan 19 12:06:31 PST 2015


Why should it throw if there's no [[Get]]?

Consider let {x} = o as short for let x = o.x (with o evaluated once and 
first, in the general case, of course). Then the empty object pattern 
does nothing and should not throw.

This seem best for generated code purposes, it gives a more general 
basis case.

/be



Axel Rauschmayer wrote:
> If I understand the spec correctly, destructuring works as follows:
>
> ```js
> let {} = undefined; // OK???
> let {x} = undefined; // TypeError
>
> let [] = undefined; // TypeError
> let [y] = undefined; // TypeError
> ```
>
> Destructuring `undefined` (or `null`) via `{}` does not throw an 
> exception (as per first rule inside [1]). Shouldn’t it throw one?
>
> Thanks!
>
> Axel
>
>
> [1] 
> https://people.mozilla.org/~jorendorff/es6-draft.html#sec-runtime-semantics-destructuringassignmentevaluation 
> <https://people.mozilla.org/%7Ejorendorff/es6-draft.html#sec-runtime-semantics-destructuringassignmentevaluation>
>
> -- 
> Dr. Axel Rauschmayer
> axel at rauschma.de <mailto:axel at rauschma.de>
> rauschma.de
>
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss


More information about the es-discuss mailing list