Destructuring `undefined` and `null`
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.
see ecmascript#3574
already fix in my working draft
On Jan 19, 2015, at 12:06 PM, Brendan Eich wrote:
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.
let { } = x;
is probably something that should never be written or generated. But consider:
{x:{ }} = x; asserts: the RHS must be coercible to an object that has an 'x' property that is coercible to an object
compared to:
{x: { }={}} = x; asserts: the RHS must be coercible to an object and if it has an 'x' property its value must be coercible to an object
compared to:
{ } = x asserts RHS must be coercible to an object
compared to:
[ ] = x asserts RHS must be coercible to an Iterable object.
Allen Wirfs-Brock wrote:
see ecmascript#3574
already fix in my working draft
Ok, so the ToObject always runs first. Sounds better on short reflection
If I understand the spec correctly, destructuring works as follows:
let {} = undefined; // OK??? let {x} = undefined; // TypeError let [] = undefined; // TypeError let [y] = undefined; // TypeErrorDestructuring
undefined(ornull) via{}does not throw an exception (as per first rule inside 1). Shouldn’t it throw one?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 -- Dr. Axel Rauschmayer axel at rauschma.de rauschma.de -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150119/035b2db4/attachment.html>