jquery core: extend() now supports deep + extending jquery itself
cached some vars and it proved to be faster.
This commit is contained in:
parent
17b1e407d1
commit
cd455eeba7
1 changed files with 9 additions and 7 deletions
16
src/core.js
16
src/core.js
|
@ -566,9 +566,9 @@ jQuery.extend = jQuery.fn.extend = function() {
|
||||||
target = {};
|
target = {};
|
||||||
|
|
||||||
// extend jQuery itself if only one argument is passed
|
// extend jQuery itself if only one argument is passed
|
||||||
if ( length == 1 ) {
|
if ( length == i ) {
|
||||||
target = this;
|
target = this;
|
||||||
i = 0;
|
--i;
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( ; i < length; i++ )
|
for ( ; i < length; i++ )
|
||||||
|
@ -576,17 +576,19 @@ jQuery.extend = jQuery.fn.extend = function() {
|
||||||
if ( (options = arguments[ i ]) != null )
|
if ( (options = arguments[ i ]) != null )
|
||||||
// Extend the base object
|
// Extend the base object
|
||||||
for ( var name in options ) {
|
for ( var name in options ) {
|
||||||
|
var src = target[ name ], copy = options[ name ];
|
||||||
|
|
||||||
// Prevent never-ending loop
|
// Prevent never-ending loop
|
||||||
if ( target === options[ name ] )
|
if ( target === copy )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Recurse if we're merging object values
|
// Recurse if we're merging object values
|
||||||
if ( deep && options[ name ] && typeof options[ name ] == "object" && target[ name ] && !options[ name ].nodeType )
|
if ( deep && copy && typeof copy == "object" && src && !copy.nodeType )
|
||||||
target[ name ] = jQuery.extend( deep, target[ name ], options[ name ] );
|
target[ name ] = jQuery.extend( deep, src, copy );
|
||||||
|
|
||||||
// Don't bring in undefined values
|
// Don't bring in undefined values
|
||||||
else if ( options[ name ] != undefined )
|
else if ( copy != undefined )
|
||||||
target[ name ] = options[ name ];
|
target[ name ] = copy;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue