# Spead assignment operator

**URL:** <https://es.discourse.group/t/spead-assignment-operator/169>\
**Category:** 💡 Ideas\
**Created:** [December 19, 2019, 4:08pm UTC](https://es.discourse.group/t/spead-assignment-operator/169 "2019-12-19T16:08:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![askpeter](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@askpeter](https://es.discourse.group/u/askpeter)\
**Post date:** [December 19, 2019, 4:08pm UTC](https://es.discourse.group/t/spead-assignment-operator/169/1 "2019-12-19T16:08:15Z")

</div>

Since its introduction in ES6, the spead operator (`...`) has found many uses.

I often find myself extending an object or array like this:

```javascript
a = {
    ...a,
    ...b,
};

```

What about adding an assignment operator (like `a += 3`) but for the spead operator:

```javascript
a ...= b;

// or

a ...= {
    foo: 'bar',
};

```

---

<div class="post-metadata">

**Author:** ![claudepache](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/claudepache/32/236_2.png) [@claudepache](https://es.discourse.group/u/claudepache)\
**Post date:** [December 19, 2019, 5:00pm UTC](https://es.discourse.group/t/spead-assignment-operator/169/2 "2019-12-19T17:00:13Z")

</div>

The issue with the proposed `a ...= b` syntax, is that the `...` operator has different meanings depending on context, and that context is lacking in `...=`. More specifically:

```javascript
a = [...a, ...b];

```

Here, `a` and `b` are considered as iterables (as are arrays, sets, maps, generators), and the `...` operator iterates over the corresponding values or entries.

```javascript
a = { ...a, ...b };

```

Here, `a` and `b` are considered as objects, and the `...` operator iterates over the corresponding properties

```javascript
a ...= b

```

Should `b` be treated as iterable or as object—knowing that a value is often both? A careful introspection on `a` and/or `b` may help to guess the intent, but the guess may be wrong.

* * *

BTW, instead of the proposed `a ...= b`, you can already write as of today: `Object.assign(a, b)`.  
.
