From b59107f5d7451ac16a7c8755128719be6ec8bf12 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Micha=C5=82=20Go=C5=82=C4=99biowski-Owczarek?= Date: Tue, 24 Sep 2019 02:12:36 +0200 Subject: [PATCH] Core: Remove private copies of push, sort & splice from the jQuery prototype Closes gh-4473 --- src/core.js | 8 +------- src/selector.js | 6 +++--- src/selector/uniqueSort.js | 7 ++++--- src/var/sort.js | 7 +++++++ 4 files changed, 15 insertions(+), 13 deletions(-) create mode 100644 src/var/sort.js diff --git a/src/core.js b/src/core.js index 6dbc69eb0..0999da9f5 100644 --- a/src/core.js +++ b/src/core.js @@ -120,13 +120,7 @@ jQuery.fn = jQuery.prototype = { end: function() { return this.prevObject || this.constructor(); - }, - - // For internal use only. - // Behaves like an Array's method, not like a jQuery method. - push: push, - sort: arr.sort, - splice: arr.splice + } }; jQuery.extend = jQuery.fn.extend = function() { diff --git a/src/selector.js b/src/selector.js index 847d3a448..fbfa7d1d8 100644 --- a/src/selector.js +++ b/src/selector.js @@ -190,7 +190,7 @@ function find( selector, context, results, seed ) { // Document context if ( nodeType === 9 ) { if ( ( elem = context.getElementById( m ) ) ) { - results.push( elem ); + push.call( results, elem ); } return results; @@ -199,7 +199,7 @@ function find( selector, context, results, seed ) { if ( newContext && ( elem = newContext.getElementById( m ) ) && jQuery.contains( context, elem ) ) { - results.push( elem ); + push.call( results, elem ); return results; } } @@ -1426,7 +1426,7 @@ function matcherFromGroupMatchers( elementMatchers, setMatchers ) { } while ( ( matcher = elementMatchers[ j++ ] ) ) { if ( matcher( elem, context || document, xml ) ) { - results.push( elem ); + push.call( results, elem ); break; } } diff --git a/src/selector/uniqueSort.js b/src/selector/uniqueSort.js index cf70d5c1a..a0454812a 100644 --- a/src/selector/uniqueSort.js +++ b/src/selector/uniqueSort.js @@ -1,7 +1,8 @@ define( [ "../core", - "../var/document" -], function( jQuery, document ) { + "../var/document", + "../var/sort" +], function( jQuery, document, sort ) { "use strict"; @@ -61,7 +62,7 @@ jQuery.uniqueSort = function( results ) { hasDuplicate = false; - results.sort( sortOrder ); + sort.call( results, sortOrder ); if ( hasDuplicate ) { while ( ( elem = results[ i++ ] ) ) { diff --git a/src/var/sort.js b/src/var/sort.js new file mode 100644 index 000000000..a943fa77c --- /dev/null +++ b/src/var/sort.js @@ -0,0 +1,7 @@ +define( [ + "./arr" +], function( arr ) { + "use strict"; + + return arr.sort; +} ); -- 2.39.5