Skip to content

Instantly share code, notes, and snippets.

@jimbojw
Created March 31, 2010 16:31
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 jimbojw/350538 to your computer and use it in GitHub Desktop.
Save jimbojw/350538 to your computer and use it in GitHub Desktop.
/**
* Extend one object with the properties of any other object(s).
* @param obj The object to extend.
* @param args Additional arguments - the objects from which to copy properties.
* @return The object which was extended.
*/
var extend = (function(){
var
slice = Array.prototype.slice,
has = Object.prototype.hasOwnProperty;
function extend( obj /*, args ... */ ) {
var args = slice.call(arguments, 1);
for (var i=0, l=args.length; i<l; i++) {
var other = args[i];
if (other) {
for (var k in other) {
if (has.call(other, k)) {
obj[k] = other[k];
}
}
}
}
return obj;
}
return extend;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment