X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fcore.js;h=23d40bd092d263bb425cfba9ab14a7825630faae;hb=dc4c9abc39ce7eda44ff8878d476db1e57b7bc46;hp=9cb519be574742f1fa8a86f99a677262a9cda674;hpb=c8dd49f756562fef68f664869952e4f5aab08acd;p=jquery.git diff --git a/src/core.js b/src/core.js index 9cb519b..23d40bd 100644 --- a/src/core.js +++ b/src/core.js @@ -306,7 +306,7 @@ jQuery.fn.init.prototype = jQuery.fn; jQuery.extend = jQuery.fn.extend = function() { // copy reference to target object - var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options, name, src, copy; + var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options, name, src, copy, copyIsArray; // Handle a deep copy situation if ( typeof target === "boolean" ) { @@ -340,10 +340,15 @@ jQuery.extend = jQuery.fn.extend = function() { continue; } - // Recurse if we're merging object literal values or arrays - if ( deep && copy && ( jQuery.isPlainObject(copy) || jQuery.isArray(copy) ) ) { - var clone = src && ( jQuery.isPlainObject(src) || jQuery.isArray(src) ) ? src - : jQuery.isArray(copy) ? [] : {}; + // Recurse if we're merging plain objects or arrays + if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) { + if ( copyIsArray ) { + copyIsArray = false; + clone = src && jQuery.isArray(src) ? src : []; + + } else { + clone = src && jQuery.isPlainObject(src) ? src : {}; + } // Never move original objects, clone them target[ name ] = jQuery.extend( deep, clone, copy ); @@ -476,7 +481,7 @@ jQuery.extend({ // A crude way of determining if an object is a window isWindow: function( obj ) { - return "setInterval" in obj; + return obj && typeof obj === "object" && "setInterval" in obj; }, type: function( obj ) {