src.js
function mergeObject (oldObject, newObject) {
  let oldCopy = Object.assign({}, oldObject)

  function _merge (oo, no) {
    for (let key in no) {
      if (key in oo) {
        // Follow structure of oo
        if (oo[key] === Object(oo[key])) {
          _merge(oo[key], no[key])
        } else if (no[key] !== Object(no[key])) {
          oo[key] = no[key]
        }
      } else {
        // Plain assign
        oo[key] = no[key]
      }
    }
    return oo
  }

  return _merge(oldCopy, newObject)
}
function mergeObject (oldObject, newObject) {
  let oldCopy = Object.assign({}, oldObject)

  function _merge (oo, no) {
    for (let key in no) {
      if (key in oo) {
        // Follow structure of oo
        if (oo[key] === Object(oo[key])) {
          _merge(oo[key], no[key])
        } else if (no[key] !== Object(no[key])) {
          oo[key] = no[key]
        }
      } else {
        // Plain assign
        oo[key] = no[key]
      }
    }
    return oo
  }

  return _merge(oldCopy, newObject)
}
function mergeObject ( oldObject , newObject ) { let oldCopy = Object . assign ( { } , oldObject ) function _merge ( oo , no ) { for ( let key in no ) { if ( key in oo ) { // Follow structure of oo if ( oo [ key ] === Object ( oo [ key ] ) ) { _merge ( oo [ key ] , no [ key ] ) } else if ( no [ key ] !== Object ( no [ key ] ) ) { oo [ key ] = no [ key ] } } else { // Plain assign oo [ key ] = no [ key ] } } return oo } return _merge ( oldCopy , newObject ) }
Merge two objects with nested data
Merge two objects with nested data