Created
November 9, 2011 08:27
-
-
Save jiggliemon/1350840 to your computer and use it in GitHub Desktop.
Merge in values from other objects that share the master objects properties.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(typeof Object.merge !== 'function') | |
Object.merge = function() { | |
var base = arguments[0] | |
args = Array.prototype.slice.call(arguments,1), | |
count = args.length, | |
keys = Object.keys(base), | |
mergeIn = undefined,key = undefined,i = 0; | |
mergeIn = function(obj){ | |
var keys = Object.keys(this), | |
key; | |
for(key in obj){ | |
if(obj.hasOwnProperty(key) && keys.indexOf(key) >= 0){ | |
this[key] = obj[key]; | |
} | |
} | |
} | |
for (;i < count; i++){ | |
mergeIn.call(base,args[i]); | |
} | |
return base; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment