Skip to content

Instantly share code, notes, and snippets.

@andyexeter
Last active September 13, 2018 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyexeter/537c6153bd71bb97c785aa83138bb9df to your computer and use it in GitHub Desktop.
Save andyexeter/537c6153bd71bb97c785aa83138bb9df to your computer and use it in GitHub Desktop.
JavaScript function to extend an object
/**
* 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