Javascript Object merge(original, extended)

Description

Javascript Object merge(original, extended)


merge = function (original, extended) {
  for (var key in extended) {
    var ext = extended[key];
    if (typeof (ext) != 'object' || ext instanceof Class) {
      original[key] = ext;/*from  w w  w.j a  v a2  s .  c  o m*/
    } else {
      if (!original[key] || typeof (original[key]) != 'object') {
        original[key] = {};
      }
      merge(original[key], ext);
    }
  }
  return original;
};



PreviousNext

Related