Skip to content
Permalink
Browse files

jquery core: extend() now supports deep + extending jquery itself

cached some vars and it proved to be faster.
  • Loading branch information
flesler committed Apr 30, 2008
1 parent 17b1e40 commit cd455eeba7ef754f35a36b10ca27a31c14bb8a1f
Showing with 9 additions and 7 deletions.
  1. +9 −7 src/core.js
@@ -566,27 +566,29 @@ jQuery.extend = jQuery.fn.extend = function() {
target = {};

// extend jQuery itself if only one argument is passed
if ( length == 1 ) {
if ( length == i ) {
target = this;
i = 0;
--i;
}

for ( ; i < length; i++ )
// Only deal with non-null/undefined values
if ( (options = arguments[ i ]) != null )
// Extend the base object
for ( var name in options ) {
var src = target[ name ], copy = options[ name ];

// Prevent never-ending loop
if ( target === options[ name ] )
if ( target === copy )
continue;

// Recurse if we're merging object values
if ( deep && options[ name ] && typeof options[ name ] == "object" && target[ name ] && !options[ name ].nodeType )
target[ name ] = jQuery.extend( deep, target[ name ], options[ name ] );
if ( deep && copy && typeof copy == "object" && src && !copy.nodeType )
target[ name ] = jQuery.extend( deep, src, copy );

// Don't bring in undefined values
else if ( options[ name ] != undefined )
target[ name ] = options[ name ];
else if ( copy != undefined )
target[ name ] = copy;

}

0 comments on commit cd455ee

Please sign in to comment.
You can’t perform that action at this time.