Skip to content

Instantly share code, notes, and snippets.

@codenothing
Created May 15, 2010 18:57
Show Gist options
  • Save codenothing/402344 to your computer and use it in GitHub Desktop.
Save codenothing/402344 to your computer and use it in GitHub Desktop.
/*
* 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