Created
May 15, 2010 18:57
-
-
Save codenothing/402344 to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
* Defined Object Extension | |
* May 15, 2010 | |
* Corey Hart @ http://www.codenothing.com | |
*/ | |
/* | |
dext( { str1: 'test1', str2: 'test2' }, { str1: 'overwrite', str3: 'wont-extend' } ); | |
=> { str1: 'overwrite', str2: 'test2' } | |
*/ | |
function dext(){ | |
var args = Array.prototype.slice.call( arguments ), target = args[0], i = 0, l = args.length, name, copy; | |
for ( ; ++i < l; ) { | |
copy = args[ i ]; | |
for ( name in copy ) { | |
if ( target.hasOwnProperty( name ) && copy.hasOwnProperty( name ) && copy[ name ] !== undefined ) { | |
target[ name ] = copy[ name ]; | |
} | |
} | |
} | |
return target; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment