Eh? The easiest way to overwrite a property is just to set it on the object:
user.online=true
Your examples are not overwriting the original object at all - they are creating a totally new object and overwriting the property on that. The original user object will remain unchanged
I forget to mention a context where you want to keep the original existing.
I use this method for updating states that don't need to refresh in the UI (React)
Could have probably worded it a bit differently
We're a place where coders share, stay up-to-date and grow their careers.
Eh? The easiest way to overwrite a property is just to set it on the object:
Your examples are not overwriting the original object at all - they are creating a totally new object and overwriting the property on that. The original
userobject will remain unchangedI wonder if in this context "Rewriting JavaScript object properties" might be a better way of putting it.
Strangely enough "updating" an Elixir map
or an Elm record
creates an entirely new value as well (because everything is immutable).
You are completely right Jon,
I forget to mention a context where you want to keep the original existing.
I use this method for updating states that don't need to refresh in the UI (React)
Could have probably worded it a bit differently