Object arithmetic--operator alternative to Object.assign
Bob Myers schrieb:
Apologies if something like this has already been proposed and/or rejected for whatever reason.
I think you're looking for the same as strawman:define_properties_operator
It would be nice to have an operator alternative for Object.assign.
It uses an ":=" operator, so your example would read
obj1 := {x, y};
Bergi
On Mar 11, 2015, at 7:23 AM, Bergi wrote:
Bob Myers schrieb:
Apologies if something like this has already been proposed and/or rejected for whatever reason.
I think you're looking for the same as strawman:define_properties_operator
Apologies if something like this has already been proposed.
We have simplified object literal syntax:
{a, b}
However, I often find myself writing this:
{a: x.a, b: y.b}
Would it be possible to have a syntax such as
{x.a, y.b}
Where the property name is taken from the last segment of the property
reference, so that x.a
becomes the value of property a
?
-- Bob
On Tue, Mar 24, 2015 at 9:44 AM, Bob Myers <rtm at gol.com> wrote:
Apologies if something like this has already been proposed.
We have simplified object literal syntax:
{a, b}
However, I often find myself writing this:
{a: x.a, b: y.b}
Would it be possible to have a syntax such as
{x.a, y.b}
Where the property name is taken from the last segment of the property reference, so that
x.a
becomes the value of propertya
?
If you're taking both values from the same object, we have the syntax:
{a, b} = x;
This may or may not help you.
For different objects this is the only way I see possible with destructuring. IMO it's a bit ugly and weird to read deep destructuring:
let x = { a: 1 };
let y = { b: 2 };
let { x: { a }, y: { b } } = { x, y };
But I'd prefer Bob Myers's way:
let x = { a: 1 };
let y = { b: 2 };
{x.a, y.b}
Now that would be for destructuring. But isn't the following shorthand property assignment not destructuring:
var c = {x,y};
//so I'm thinking Bob wants the following:
var c = {x.a, b.y}; // {a: 1, b: 2}
On Tue, Mar 24, 2015 at 7:09 PM Edwin Reynoso <eorroe at gmail.com> wrote:
For different objects this is the only way I see possible with destructuring. IMO it's a bit ugly and weird to read deep destructuring:
let x = { a: 1 }; let y = { b: 2 }; let { x: { a }, y: { b } } = { x, y };
But I'd prefer Bob Myers's way:
let x = { a: 1 }; let y = { b: 2 }; {x.a, y.b}
Now that would be for destructuring. But isn't the following shorthand property assignment not destructuring:
var c = {x,y}; //so I'm thinking Bob wants the following: var c = {x.a, b.y}; // {a: 1, b: 2}
As an exercise to see if this is reasonable, I spent some time drafting an outline addition to "12.2.5.9 Runtime Semantics: PropertyDefinitionEvaluation" that handled a newly defined (ie. thing I made up) "PropertyDefinition : IdentifierNameReference", but ran into issues when I had to consider all the forms that MemberExpression includes. people.mozilla.org/~jorendorff/es6-draft.html#sec
Yea, um I'm only 16 and been programming in Javascript for about 2-3 years. I haven't gotten to the Nitty Gritty part of Javascript specs. So I won't be able to help out with that. I was just throwing out what I mentioned above.
Apologies if something like this has already been proposed and/or rejected for whatever reason.
It would be nice to have an operator alternative for Object.assign. Perhaps "dot-plus' would work:
obj1 .+ {x, y}
To mutate an existing object, "dot-plus-equals":
obj1 .+= {x, y}
-- Bob