John Gardner (2016-03-05T13:01:35.000Z)
gardnerjohng at gmail.com (2016-03-05T13:06:42.267Z)
Reading a previous proposal <http://rtm.github.io/boberator.html> for a pick operator illuminated an obvious shortcoming in ES6's deconstructor syntax: > The fundamental limitation of this feature is that it is **limited to picking into variables.** I see the problem: ```js let { p1, p2 } = o; let pickedProps = { p1, p2 }; ``` Just take a leaf from Perl's book (page 59 to be absolutely precise): ```js let pickedProps{ p1, p2 } = o; ``` Anonymous/unnamed values could be yielded by using brackets: ```js ({ p1, p2 }) = o; console.log("Value:", ({ p1, p2 }) = o); ``` Properties could be written to existing objects if they're named outside a `let/const/var` declaration: ```js let pickedProps = {p1: "Old"}; pickedProps{ p1 } = o; ``` I wouldn't want the syntax to get too fancy, but if anybody feels like property renaming should be supported, I guess it could be achieved like this (I prefer the first): ```js let pickedProps{ p1 as One, p2 as Two } = o; // ... or even: let pickedProps{ p1:One, p2:Two } = o; ``` Yes, the `as` keyword is used for importing modules, but since modules are parsed statically prior to evaluation, I can't see this causing an issue. Thoughts?
gardnerjohng at gmail.com (2016-03-05T13:06:33.414Z)
Reading a previous proposal <http://rtm.github.io/boberator.html> for a pick operator illuminated an obvious shortcoming in ES6's deconstructor syntax: > The fundamental limitation of this feature is that it is **limited to picking into variables.** I see the problem: ```js let { p1, p2 } = o; let pickedProps = { p1, p2 }; ``` Just take a leaf from Perl's book (page 59 to be absolutely precise): ```js let pickedProps{ p1, p2 } = o; ``` Anonymous/unnamed values could be yielded by using brackets: ```js ({ p1, p2 }) = o; console.log("Value:", ({ p1, p2 }) = o); ``` Properties could be written to existing objects if they're named outside a `let/const/var` declaration: ```js let pickedProps = {p1: "Old"}; pickedProps{ p1 } = o; ``` I wouldn't want the syntax to get too fancy, but if anybody feels like property renaming should be supported, I guess it could be achieved like this (I prefer the first): ```js let pickedProps{ p1 as One, p2 as Two } = o; // ... or even: let pickedProps{ p1:One, p2:Two } = o; ``` Yes, the `as` keyword is used for importing modules, but since modules are parsed statically prior to evaluation, I can't see this causing an issue. Thoughts?
gardnerjohng at gmail.com (2016-03-05T13:06:14.215Z)
Reading a previous proposal <http://rtm.github.io/boberator.html> for a pick operator illuminated an obvious shortcoming in ES6's deconstructor syntax: > The fundamental limitation of this feature is that it is **limited to picking into variables.** I see the problem: ```js let { p1, p2 } = o; let pickedProps = { p1, p2 }; ``` Just take a leaf from Perl's book (page 59 to be absolutely precise): ```js let pickedProps{ p1, p2 } = o; ``` Anonymous/unnamed values could be yielded by using brackets: ```js ({ p1, p2 }) = o; console.log("Value:", ({ p1, p2 }) = o); ``` Properties could be written to existing objects if they're named outside a `let/const/var` declaration: ```js let pickedProps = {p1: "Old"}; pickedProps{ p1 } = o; ``` I wouldn't want the syntax to get too fancy, but if anybody feels like property renaming should be supported, I guess it could be achieved like this (I prefer the first): ```js let pickedProps{ p1 as One, p2 as Two } = o; // ... or even: let pickedProps{ p1:One, p2:Two } = o; ``` Yes, the `as` keyword is used for importing modules, but since modules are parsed statically prior to evaluation, I can't see this causing an issue. Thoughts?