📘Object.assign()

JSvalueobjectextend ⟩ Object.assign()

Object.assign(target, source1, source2, ...)  // overwrite target with sources

// similar to 
{...target, ...source1, ...source2}

☢️ Alert

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