Skip to content

Instantly share code, notes, and snippets.

@LiamChapman
Last active January 1, 2016 23:59
Show Gist options
  • Select an option

  • Save LiamChapman/8219927 to your computer and use it in GitHub Desktop.

Select an option

Save LiamChapman/8219927 to your computer and use it in GitHub Desktop.
Basic object merge with javascript e.g. var myObject1 = { 'test1' }; var myObject2 = { 'test2' }; myObject = myObject1.merge(myObject2);
Object.prototype.merge = function (toMerge) {
var obj = {};
// first object
for (var i in this) {
obj[i] = this[i];
}
// second object
for (var i in toMerge) {
obj[i] = toMerge[i];
}
return obj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment