Skip to content

Instantly share code, notes, and snippets.

@premasagar
Created June 4, 2012 12:49
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 premasagar/2868143 to your computer and use it in GitHub Desktop.
Save premasagar/2868143 to your computer and use it in GitHub Desktop.
function extend(target/*, any number of source objects*/){
var i = 1,
len = arguments.length,
withPrototype = arguments[len-1] === true,
obj, prop;
target || (target = {});
for (; i < len; i++){
obj = arguments[i];
if (typeof obj === 'object'){
for (prop in obj){
if (withPrototype || obj.hasOwnProperty(prop)){
target[prop] = obj[prop];
}
}
}
}
return target;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment