Fix #1907 where the never-ending loop prevention used a coersion comparison which sometimes dropped values incorrectly. Also fixed a bug where on deep copies the target copied over itself (i = 2 addition). Last made code handle the case when a property might have a string in it that should be overwritten by an object.

This commit is contained in:
David Serduke 2007-11-17 04:25:22 +00:00
parent 6853370fbb
commit bf8f3fe094
2 changed files with 20 additions and 3 deletions

View file

@ -516,8 +516,14 @@ jQuery.extend = jQuery.fn.extend = function() {
if ( target.constructor == Boolean ) {
deep = target;
target = arguments[1] || {};
// skip the boolean and the target
i = 2;
}
// Handle case when target is a string or something (possible in deep copy)
if ( typeof target != "object" )
target = {};
// extend jQuery itself if only one argument is passed
if ( length == 1 ) {
target = this;
@ -530,12 +536,12 @@ jQuery.extend = jQuery.fn.extend = function() {
// Extend the base object
for ( var name in options ) {
// Prevent never-ending loop
if ( target == options[ name ] )
if ( target === options[ name ] )
continue;
// Recurse if we're merging object values
if ( deep && typeof options[ name ] == "object" && target[ name ] && !options[ name ].nodeType )
jQuery.extend( target[ name ], options[ name ] );
target[ name ] = jQuery.extend( target[ name ], options[ name ] );
// Don't bring in undefined values
else if ( options[ name ] != undefined )