X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fcore.js;h=2c2b7466622ab69cad829a27feecae4814d64147;hb=6dfdb14753c66cfd38f8445bd6119ef4a1274d5e;hp=f6a07eb8baef66002f3cc8bb2b63d3e2ed434796;hpb=e270d804b4cee58dbf438251e9becb6f0f2ac123;p=jquery.git diff --git a/src/core.js b/src/core.js index f6a07eb..2c2b746 100644 --- a/src/core.js +++ b/src/core.js @@ -69,7 +69,10 @@ var jQuery = function( selector, context ) { push = Array.prototype.push, slice = Array.prototype.slice, trim = String.prototype.trim, - indexOf = Array.prototype.indexOf; + indexOf = Array.prototype.indexOf, + + // [[Class]] -> type pairs + class2type = {}; jQuery.fn = jQuery.prototype = { init: function( selector, context ) { @@ -306,7 +309,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 +343,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 ); @@ -483,7 +491,7 @@ jQuery.extend({ type: function( obj ) { return obj == null ? String( obj ) : - toString.call(obj).slice(8, -1).toLowerCase(); + class2type[ toString.call(obj) ] || "object"; }, isPlainObject: function( obj ) { @@ -795,6 +803,11 @@ jQuery.extend({ browser: {} }); +// Populate the class2type map +jQuery.each("Boolean Number String Function Array Date RegExp Object".split(" "), function(i, name) { + class2type[ "[object " + name + "]" ] = name.toLowerCase(); +}); + browserMatch = jQuery.uaMatch( userAgent ); if ( browserMatch.browser ) { jQuery.browser[ browserMatch.browser ] = true;