Skip to content

Instantly share code, notes, and snippets.

@oomlaut
Created June 18, 2013 19:37
Show Gist options
  • Save oomlaut/5808558 to your computer and use it in GitHub Desktop.
Save oomlaut/5808558 to your computer and use it in GitHub Desktop.
Modify the Object prototype to allow a passed object argument to be merged in.
// http://stackoverflow.com/questions/171251/how-can-i-merge-properties-of-two-javascript-objects-dynamically
Object.prototype.merge = function(mergeFrom){
var newObj = {};
for (var attrname in this) { newObj[attrname] = this[attrname]; }
for (var attrname in mergeFrom) { newObj[attrname] = mergeFrom[attrname]; }
return newObj;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment