Constructing objects from named identifiers

Bob Myers rtm at gol.com
Thu Jun 2 19:06:42 UTC 2016


The proposal of mine referenced by John in his link is obsolete, and has
been replaced by https://github.com/rtm/js-pick-notation, with a new
minimal variation at
https://github.com/rtm/js-pick-notation/blob/master/minimal/spec.md which
precisely leverages the current syntax and semantics of deconstructing.

John's proposal for picking into an anonymous object:

```js
({p1, p2}) = o
```

overloads parentheses in a strange way, and is too easily confused with

```js
({p1, p2} = o)
```

which means a completely different thing, and furthermore violates the
semantics of the assignment operator, which is that it evaluates to the
RHS, whereas he presumably intended this to evaluate to the newly created
object.

The assignment operator `=` makes sense in current deconstructing
assignments, since it *is* an assignment. It makes no sense in the context
of picking properties into objects.

In my proposal, this is

```js
o.{p1, p2}
```

which has a clear analogy to the "single property picking" syntax `o.p1`,
is syntactically unambiguous, easily parsable using existing machinery for
parsing deconstructors, and by virtue of re-using current deconstruction
syntax allows for renaming and defaults out of the box.

I've approached a couple of possible champions for this but no dice so far.

--
Bob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160603/ee3f185b/attachment.html>


More information about the es-discuss mailing list