📘Object.assign()
JS ⟩ value ⟩ object ⟩ extend ⟩ Object.assign()
copies all enumerable own property values from sources to a target (with get/set).
and returns the modified target.
☢️ Alert:
Object.assign() copies property values (with get/set), not their attributes❗
if a source has a getter or the target has a setter, they will be invoked❗️, not copied❗️ 👉 ⛔️ Object.assign causing TypeError
use obj.mergeWith() instead if we want to copy accessors.
Object.assign()
only copies the values of enumerable properties, not their attributes❗
if one of the source objects has an accessor property, it is the value returned by the getter that is copied to the target object, not the getter itself❗
☢️ Alert:
Don't use Object.assign() with sources that have getters, the inner states of the sources may change❗❗❗ 👉 .assignDescriptors()
Last updated