# Shorthand for object property assigment

**URL:** <https://es.discourse.group/t/shorthand-for-object-property-assigment/539>\
**Category:** 💡 Ideas\
**Created:** [November 11, 2020, 10:17am UTC](https://es.discourse.group/t/shorthand-for-object-property-assigment/539 "2020-11-11T10:17:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![murka](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/murka/32/494_2.png) [@murka](https://es.discourse.group/u/murka)\
**Post date:** [November 11, 2020, 10:17am UTC](https://es.discourse.group/t/shorthand-for-object-property-assigment/539/1 "2020-11-11T10:17:52Z")

</div>

Javascript has many shorthands for assignment operator like `??=`, `&&=`, `+=` and others. Also objects can be initialized using literal notation:` const a = 5; const obj = { a };`. So how about a shorthand for property assignment which based on them?  
It's syntax is very simple. Instead of:  
`obj.prop = prop`  
We just write  
`obj .= prop`  
The rule is very simple. Shorthand is allowed on object property assignment to variable when property and variable names are equal. The syntax is intuitive and clear, IMO  
So, what do you think? Please share your opinion.

---

<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:** [November 11, 2020, 3:02pm UTC](https://es.discourse.group/t/shorthand-for-object-property-assigment/539/2 "2020-11-11T15:02:46Z")

</div>

> [@murka](#):
>
> The syntax is intuitive and clear, IMO

I disagree on that particular point.

In general, `obj <OP>= val` is roughly equivalent to `obj = obj <OP> val`; e.g.

- `obj += val` is equivalent to `obj = obj + val`, except that `obj` is evaluated only once;

- `obj ??= val` is equivalent to `obj = obj ?? val`, except that assignment may be skipped per short-circuiting semantics.

So I expect `obj .= prop` be equivalent to `obj = obj.prop`, which is completely different from you mean.

---

<div class="post-metadata">

**Author:** ![claudiameadows](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/claudiameadows/32/126_2.png) [@claudiameadows](https://es.discourse.group/u/claudiameadows)\
**Post date:** [November 23, 2020, 3:22am UTC](https://es.discourse.group/t/shorthand-for-object-property-assigment/539/3 "2020-11-23T03:22:11Z")

</div>

And this potential point of confusion makes me feel this is probably not a good idea to add.
