Extended dot notation (pick notation) proposal

Jason Orendorff jason.orendorff at gmail.com
Fri Sep 23 21:50:22 UTC 2016

On Thu, Sep 22, 2016 at 1:14 PM, Bob Myers <rtm at gol.com> wrote:

> In the proposed "pick/destructure into an object" syntax, I would use
> identical destructuring syntax
> ```
> obj.{foo: {bar: {qux}}}
> ```
> which would turn into `{qux: obj.foo.bar.qux}`.
> We are simply using identical destructuring syntax to destructure into an
> object instead of a variable.

I'm sorry, Bob, the link in your original post in this thread has a link to
the proposal; it's perfectly clear on this, and I should have gone back to

OK, I  think I understand the proposal now. A few comments:

1.  The gist says:

    > The syntax of the *Assignment Pattern* is identical.

    I don't think this is right; I think you want all the right-hand sides
of all the properties in the tree to match PropertyName. In
AssignmentPattern, those can be any LeftHandSideExpression:

        {text: f().q[13].name} = obj;

    But that wouldn't make sense in pick notation:

        obj.{text: f().q[13].name}  // ???

2.  I mentioned scoping earlier. What I mean is, in expressions like

        obj.{[p]: p}

    the two identifiers `p` mean different things (the first `p` is a
variable name, the second `p` a property name), which is new and subtle.
The same thing happens in `obj.{p = p}`, except the other way round.
Destructuring does just a touch of this in the shorthand case, but I never
found that confusing. This is.

3.  I wonder if this can be made more symmetrical -- as it stands, it
allows you to flatten a complex object:

        // from a tree of 3 objects to one
        let rect = corners.{
            p0: {x: left, y: top},
            p1: {x: right, y: bottom}

    The reverse would be to add structure to a flat object. There's no way
to do that, right?

        // turn the 1 object back into a tree of 3?
        let corners = rect.{ ??? };

    Likewise, it seems you can turn an array into a plain object, but not
the other way around?

        let point = coords.[x, y];   // {x: coords[0], y: coords[1]}
        let coords = point.{???};   // [point.x, point.y]

    Honestly even the examples that do work seem ugly to me. I think pretty
much all the value in the proposal is in the simplest case,
`obj.{identifier, ...}`.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160923/6f6ba90a/attachment.html>

More information about the es-discuss mailing list