destructuring: as patterns?

David Nolen dnolen.lists at
Wed Apr 18 14:37:57 PDT 2012

On Wed, Apr 18, 2012 at 5:35 PM, David Herman <dherman at> wrote:

> Agreed. This is easy to spec and implement, highly composable (it fits
> neatly into the algebra of destructuring patterns everywhere, as opposed to
> just in object property-name positions), has no problems with side effects,
> and does not violate restrictions that IINM strict mode is supposed to ban
> (repeated property names in literals).
> The repeated property-name thing is a hack. It does not Say What You Mean
> (it's a total surprise). It is not composable (it only works for property
> names, not for array indices).
> Worst of all, it will trigger getters twice:
>    > let { b, b: { x, y } } = { get b() { console.log("BOO!"); return 17 }
> }
>    BOO!
>    BOO!
> But if that's the only way to do it, then if you want to destructure a
> getter, you will be forced not to use the hack, and to bind a temporary
> variable and do a second destructuring on a second line.
> *Please*, let's do this right. There's no reason to introduce hacks. I'm
> open to various syntaxes, but I think `as` is nice especially because it
> could work well for import/export syntax too. Lots of people complain about
> confusion over which is the bound name and which is the label. IINM, we
> could allow both:
>    let { x: x as y } = obj;
> and
>    let { x as y } = obj;
> which would be a nice idiom for making it more obvious that x is the label
> and y is the binding. Then this would be especially nice for imports:
>    import { x as y } from X;
> Dave

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list