Another option that feels intuitive to me is: let { a, b: ({ x, y }) } = object;
Parentesis imply that I want both parent and matched children. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Wednesday, 2012-04-18 at 09:01 , Irakli Gozalishvili wrote: > > > On Wednesday, 2012-04-18 at 08:26 , Brendan Eich wrote: > > > 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. > > > > To be honest I've being running into cases where I wished I could match both > parent and children in some way. Also, I think that Herby's version is > better in fact I had to learn that it's illegal. Unless it's too much of a > deal I'd also like following to work: > > let { a, b, b: { x, y } } = object; > > > /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 > > > es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) > > > https://mail.mozilla.org/listinfo/es-discuss > > > > > > > _______________________________________________ > > es-discuss mailing list > > es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) > > https://mail.mozilla.org/listinfo/es-discuss > > > > > > > >
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss