Created
February 20, 2013 10:30
-
-
Save adamcbrewer/4994571 to your computer and use it in GitHub Desktop.
JS: Extending/merging one object with another.
This file contains 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
/** | |
* An extend function to merge some default arguments | |
* with those passed in from the user. | |
* | |
* @param {object} obj The default settings | |
* @param {object} extObj Arguments from the user | |
* @return {object} A merged object | |
* | |
*/ | |
var extend = function (obj, extObj) { | |
if (arguments.length > 2) { | |
var a = 1; | |
for (a; a < arguments.length; a++) { | |
extend(obj, arguments[a]); | |
} | |
} else { | |
for (var i in extObj) { | |
obj[i] = extObj[i]; | |
} | |
} | |
return obj; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment