Proposal: spread assignment operator

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Proposal: spread assignment operator

Артём Арутюнян
I propose spread assignment operator:
 
var obj = { test1: 1 };
var anotherObj = { test2: 2 };
obj ...= { test2: 2 }; // == (obj = { ...obj, ...anotherObj })
// { test1: 1, test2: 2 }
 
I'm surprised it wasn't in the original implementation

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: spread assignment operator

Isiah Meadows-2
Note: `Object.assign` mutates its first argument and (with only obscure caveats) does exactly this. Not sure syntax is necessary here.

Oh, and arrays also have the common idiom `array.push(...values)` (but they could use an `Array.prototype.pushAll` to avoid polluting arguments lists).

On Wed, Apr 25, 2018, 09:24 Артём Арутюнян <[hidden email]> wrote:
I propose spread assignment operator:
 
var obj = { test1: 1 };
var anotherObj = { test2: 2 };
obj ...= { test2: 2 }; // == (obj = { ...obj, ...anotherObj })
// { test1: 1, test2: 2 }
 
I'm surprised it wasn't in the original implementation
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: spread assignment operator

Артём Арутюнян
spread assignment not mutate, it reassign, like "+=" and other.
 
if (
('a = {...a,...b}'.length > 'a ...= b'.length) === ('n = n+1'.length > 'n += 1'.length)
) { console.log('why "addition assignment" is necessary, but "spread assignment" is not?'); }
 
 
 
25.04.2018, 18:21, "Isiah Meadows" <[hidden email]>:
Note: `Object.assign` mutates its first argument and (with only obscure caveats) does exactly this. Not sure syntax is necessary here.
 
Oh, and arrays also have the common idiom `array.push(...values)` (but they could use an `Array.prototype.pushAll` to avoid polluting arguments lists).
 
On Wed, Apr 25, 2018, 09:24 Артём Арутюнян <[hidden email]> wrote:
I propose spread assignment operator:
 
var obj = { test1: 1 };
var anotherObj = { test2: 2 };
obj ...= { test2: 2 }; // == (obj = { ...obj, ...anotherObj })
// { test1: 1, test2: 2 }
 
I'm surprised it wasn't in the original implementation
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: spread assignment operator

Isiah Meadows-2
It doesn't. But with objects, it's not a cheap operation to simply duplicate, and they aren't normally immutable like primitives. Furthermore, why is it for objects, not arrays?

(I'm pushing that second question as a point of potential confusion - remember the user.)

On Wed, Apr 25, 2018, 11:45 Arutyunyan Artyom <[hidden email]> wrote:
spread assignment not mutate, it reassign, like "+=" and other.
 
if (
('a = {...a,...b}'.length > 'a ...= b'.length) === ('n = n+1'.length > 'n += 1'.length)
) { console.log('why "addition assignment" is necessary, but "spread assignment" is not?'); }
 
 
 
25.04.2018, 18:21, "Isiah Meadows" <[hidden email]>:
Note: `Object.assign` mutates its first argument and (with only obscure caveats) does exactly this. Not sure syntax is necessary here.
 
Oh, and arrays also have the common idiom `array.push(...values)` (but they could use an `Array.prototype.pushAll` to avoid polluting arguments lists).
 
On Wed, Apr 25, 2018, 09:24 Артём Арутюнян <[hidden email]> wrote:
I propose spread assignment operator:
 
var obj = { test1: 1 };
var anotherObj = { test2: 2 };
obj ...= { test2: 2 }; // == (obj = { ...obj, ...anotherObj })
// { test1: 1, test2: 2 }
 
I'm surprised it wasn't in the original implementation
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: spread assignment operator

Артём Арутюнян
 
I think it can be looks like: https://gist.github.com/artalar/ea8512546a3675648615a25e846096a6
 
25.04.2018, 18:58, "Isiah Meadows" <[hidden email]>:
It doesn't. But with objects, it's not a cheap operation to simply duplicate, and they aren't normally immutable like primitives. Furthermore, why is it for objects, not arrays?
 
(I'm pushing that second question as a point of potential confusion - remember the user.)
 
On Wed, Apr 25, 2018, 11:45 Arutyunyan Artyom <[hidden email]> wrote:
spread assignment not mutate, it reassign, like "+=" and other.
 
if (
('a = {...a,...b}'.length > 'a ...= b'.length) === ('n = n+1'.length > 'n += 1'.length)
) { console.log('why "addition assignment" is necessary, but "spread assignment" is not?'); }
 
 
 
25.04.2018, 18:21, "Isiah Meadows" <[hidden email]>:
Note: `Object.assign` mutates its first argument and (with only obscure caveats) does exactly this. Not sure syntax is necessary here.
 
Oh, and arrays also have the common idiom `array.push(...values)` (but they could use an `Array.prototype.pushAll` to avoid polluting arguments lists).
 
On Wed, Apr 25, 2018, 09:24 Артём Арутюнян <[hidden email]> wrote:
I propose spread assignment operator:
 
var obj = { test1: 1 };
var anotherObj = { test2: 2 };
obj ...= { test2: 2 }; // == (obj = { ...obj, ...anotherObj })
// { test1: 1, test2: 2 }
 
I'm surprised it wasn't in the original implementation
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: spread assignment operator

Jeremy Martin
By way of context, some similar ideas have been previously discussed:
FWIW, I actually do like the idea of being able to syntactically "reshape" one object or array directly into another, and there's probably even a cowpath argument to be made on the basis of so many `pick()`, `omit()`, etc. implementations out there. On the other hand, per Isiah's comments, we're at least 90% there already with Object.assign(), so it seems like the value proposition could/should be developed a bit more on this.

On Wed, Apr 25, 2018 at 12:29 PM, Arutyunyan Artyom <[hidden email]> wrote:
 
 
25.04.2018, 18:58, "Isiah Meadows" <[hidden email]>:
It doesn't. But with objects, it's not a cheap operation to simply duplicate, and they aren't normally immutable like primitives. Furthermore, why is it for objects, not arrays?
 
(I'm pushing that second question as a point of potential confusion - remember the user.)
 
On Wed, Apr 25, 2018, 11:45 Arutyunyan Artyom <[hidden email]> wrote:
spread assignment not mutate, it reassign, like "+=" and other.
 
if (
('a = {...a,...b}'.length > 'a ...= b'.length) === ('n = n+1'.length > 'n += 1'.length)
) { console.log('why "addition assignment" is necessary, but "spread assignment" is not?'); }
 
 
 
25.04.2018, 18:21, "Isiah Meadows" <[hidden email]>:
Note: `Object.assign` mutates its first argument and (with only obscure caveats) does exactly this. Not sure syntax is necessary here.
 
Oh, and arrays also have the common idiom `array.push(...values)` (but they could use an `Array.prototype.pushAll` to avoid polluting arguments lists).
 
On Wed, Apr 25, 2018, 09:24 Артём Арутюнян <[hidden email]> wrote:
I propose spread assignment operator:
 
var obj = { test1: 1 };
var anotherObj = { test2: 2 };
obj ...= { test2: 2 }; // == (obj = { ...obj, ...anotherObj })
// { test1: 1, test2: 2 }
 
I'm surprised it wasn't in the original implementation
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss




--
Jeremy Martin
661.312.3853

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss