Removed the need for the results set to have array methods. Resolves jQuery bug #4250.

This commit is contained in:
John Resig 2009-02-25 18:41:29 +00:00
parent f094c803de
commit 58235cc38e
2 changed files with 13 additions and 15 deletions

View file

@ -279,14 +279,9 @@ jQuery.fn = jQuery.prototype = {
return this.prevObject || jQuery(null);
},
// For internal use only.
// Behaves like an Array's method, not like a jQuery method.
push: [].push,
sort: [].sort,
splice: [].splice,
find: function( selector ) {
var ret = this.pushStack( "", "find", selector ), length = 0;
var ret = this.pushStack( "", "find", selector ), length = 0,
splice = Array.prototype.splice;
for ( var i = 0, l = this.length; i < l; i++ ) {
length = ret.length;
@ -297,7 +292,7 @@ jQuery.fn = jQuery.prototype = {
for ( var n = length; n < ret.length; n++ ) {
for ( var r = 0; r < length; r++ ) {
if ( ret[r] === ret[n] ) {
ret.splice(n--, 1);
splice.call(ret, n--, 1);
break;
}
}

View file

@ -8,7 +8,10 @@
var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?/g,
done = 0,
toString = Object.prototype.toString;
toString = Object.prototype.toString,
arraySplice = Array.prototype.splice,
arrayPush = Array.prototype.push,
arraySort = Array.prototype.sort;
var Sizzle = function(selector, context, results, seed) {
results = results || [];
@ -104,17 +107,17 @@ var Sizzle = function(selector, context, results, seed) {
if ( toString.call(checkSet) === "[object Array]" ) {
if ( !prune ) {
results.push.apply( results, checkSet );
arrayPush.apply( results, checkSet );
} else if ( context && context.nodeType === 1 ) {
for ( var i = 0; checkSet[i] != null; i++ ) {
if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && contains(context, checkSet[i])) ) {
results.push( set[i] );
arrayPush.call( results, set[i] );
}
}
} else {
for ( var i = 0; checkSet[i] != null; i++ ) {
if ( checkSet[i] && checkSet[i].nodeType === 1 ) {
results.push( set[i] );
arrayPush.call( results, set[i] );
}
}
}
@ -133,12 +136,12 @@ var Sizzle = function(selector, context, results, seed) {
Sizzle.uniqueSort = function(results){
if ( sortOrder ) {
hasDuplicate = false;
results.sort(sortOrder);
arraySort.call(results, sortOrder);
if ( hasDuplicate ) {
for ( var i = 1; i < results.length; i++ ) {
if ( results[i] === results[i-1] ) {
results.splice(i--, 1);
arraySplice.call(results, i--, 1);
}
}
}
@ -663,7 +666,7 @@ var makeArray = function(array, results) {
array = Array.prototype.slice.call( array );
if ( results ) {
results.push.apply( results, array );
arrayPush.apply( results, array );
return results;
}