]> source.dussan.org Git - jquery.git/commitdiff
jquery core: extend() now supports deep + extending jquery itself
authorAriel Flesler <aflesler@gmail.com>
Wed, 30 Apr 2008 00:09:55 +0000 (00:09 +0000)
committerAriel Flesler <aflesler@gmail.com>
Wed, 30 Apr 2008 00:09:55 +0000 (00:09 +0000)
cached some vars and it proved to be faster.

src/core.js

index 1353ebad2b66ac5edcff4bca9406bc97bd0bc99b..80115b44278daab14aa8be5e141eee4f3a450dbd 100644 (file)
@@ -566,9 +566,9 @@ 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++ )
@@ -576,17 +576,19 @@ jQuery.extend = jQuery.fn.extend = function() {
                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;
 
                        }