Created
March 31, 2010 16:31
-
-
Save jimbojw/350538 to your computer and use it in GitHub Desktop.
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
/** | |
* 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