extend

Prev Top Next
// function(dest, source, source, ...)
function extend(dest){
  var source, attr;
  for (var i = 1; i < arguments.length; i++){
    source = arguments[i];
    for (attr in source){
      dest[attr] = source[attr];
    }
  }
}

var obj1 = {
  obj1Prop: true
};

var obj2 = {
  obj2Prop: true
};

extend(obj1, obj2);

assertDeepEqual(obj1, { obj1Prop: true, obj2Prop: true }, "merges properties onto destination");
assertDeepEqual(obj2, { obj2Prop: true }, "doesn't modify source object");