We've supported destructuring for years and no one has asked for this. I
say YAGNI and when in doubt, leave it out. One can always write two
destructuring declarations without much repetition:
let {b} = obj;
let {x,y} = b;
but of course one would just write
let {x, y} = obj.b;
in that contrived case.
Main thing is, not having as-patterns is not a big deal based on
experience with JS1.7+ since 2006 in Mozilla code.
/be
Claus Reinke wrote:
Looking through the destructuring proposal
http://wiki.ecmascript.org/doku.php?id=harmony:destructuring
there seems to be no mention of 'as' patterns. In typical pattern
matching constructs (SML, Haskell, ..), 'as' patterns allow to name a
sub-object while continuing the match for its sub-structures.
For instance, with
var obj = { a: 0, b: { x: 1, y: 2} };
something like
let { b: b as {x,y} } = obj
would result in the bindings of b to obj.b, x to obj.b.x, y to obj.b.y.
This avoids needless repetition when both a subobject and its
components need to be extracted. Without 'as', each such case
leads to a separate destructuring assignment
let { b } = obj
let { b: {x,y} } = obj
Shouldn't 'as' patterns be included in destructuring? Or have I
missed an equivalent feature?
Claus
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss