Last active
September 13, 2018 10:36
-
-
Save andyexeter/537c6153bd71bb97c785aa83138bb9df to your computer and use it in GitHub Desktop.
JavaScript function to extend an object
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
/** | |
* Extends obj by adding the properties of all other objects passed to the function. | |
* | |
* @param {...Object} obj | |
* @returns {Object} The extended object. | |
*/ | |
function extend(obj) { | |
for (var i = 1; i < arguments.length; i++) { | |
for (var key in arguments[i]) { | |
if (arguments[i].hasOwnProperty(key)) { | |
obj[key] = arguments[i][key]; | |
} | |
} | |
} | |
return obj; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment