X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fjquery%2Fjquery.js;h=1d2e197970b002b31219ac29ca4066dc4913e1b6;hb=8c15e852a4614ba5a5100e1c6e8a833c39b4ca79;hp=b7091e26fa97c1b2924966cf3cc73748175ed50f;hpb=2ef4093cf7f52383dd43bd361864edcda27e5c3c;p=jquery.git diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js index b7091e2..1d2e197 100644 --- a/src/jquery/jquery.js +++ b/src/jquery/jquery.js @@ -301,7 +301,7 @@ jQuery.fn = jQuery.prototype = { */ setArray: function( a ) { this.length = 0; - [].push.apply( this, a ); + Array.prototype.push.apply( this, a ); return this; }, @@ -1160,6 +1160,10 @@ jQuery.fn = jQuery.prototype = { ( this.length ? this[0].innerHTML : null ) : this.empty().append( val ); }, + + slice: function() { + return this.pushStack( Array.prototype.slice.apply( this, arguments ) ); + }, /** * @private @@ -1252,7 +1256,13 @@ jQuery.fn = jQuery.prototype = { */ jQuery.extend = jQuery.fn.extend = function() { // copy reference to target object - var target = arguments[0] || {}, a = 1, al = arguments.length; + var target = arguments[0] || {}, a = 1, al = arguments.length, deep = false; + + // Handle a deep copy situation + if ( target.constructor == Boolean ) { + deep = target; + target = arguments[1] || {}; + } // extend jQuery itself if only one argument is passed if ( al == 1 ) { @@ -1272,7 +1282,7 @@ jQuery.extend = jQuery.fn.extend = function() { continue; // Recurse if we're merging object values - if ( typeof prop[i] == 'object' && target[i] ) + if ( deep && typeof prop[i] == 'object' && target[i] ) jQuery.extend( target[i], prop[i] ); // Don't bring in undefined values @@ -1387,12 +1397,24 @@ jQuery.extend({ */ // args is for internal usage only each: function( obj, fn, args ) { - if ( obj.length == undefined ) - for ( var i in obj ) - fn.apply( obj[i], args || [i, obj[i]] ); - else - for ( var i = 0, ol = obj.length; i < ol; i++ ) - if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break; + if ( args ) { + if ( obj.length == undefined ) + for ( var i in obj ) + fn.apply( obj[i], args ); + else + for ( var i = 0, ol = obj.length; i < ol; i++ ) + if ( fn.apply( obj[i], args ) === false ) break; + + // A special, fast, case for the most common use of each + } else { + if ( obj.length == undefined ) + for ( var i in obj ) + fn.call( obj[i], i, obj[i] ); + else + for ( var i = 0, ol = obj.length, val = obj[0]; + i < ol && fn.call(val,i,val) !== false; val = obj[++i] ); + } + return obj; },