tc39/proposal-logical-assignment

Property assignment operator

btoo opened this issue · 4 comments

btoo commented

Not sure if here is the right place to mention this, but could this proposal include a property assignment operator such as .= that would assign the value of an object using the name of the variable as the key for the property to update:
given

let objectWithProperty = { property: 'originalValue' }

you could

let property = 'newValue'
objectWithProperty .= property
console.log(objectWithProperty.property) // newValue

Does it create the object on the fly if it doesn't already exist?

btoo commented

I would think it doesn't, much in the same way i += 2 wouldn't work unless i was already defined.

I really only thought of this suggestion as a shorthand for

objectWithProperty.property = property

This suggestion seems like a different proposal.

Yah, this is very different than logical assignment.