]> source.dussan.org Git - jquery.git/commitdiff
Core: Remove private copies of push, sort & splice from the jQuery prototype
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>
Tue, 24 Sep 2019 00:12:36 +0000 (02:12 +0200)
committerGitHub <noreply@github.com>
Tue, 24 Sep 2019 00:12:36 +0000 (02:12 +0200)
Closes gh-4473

src/core.js
src/selector.js
src/selector/uniqueSort.js
src/var/sort.js [new file with mode: 0644]

index 6dbc69eb083b34f5ce08418a16fc2b999742684a..0999da9f563ef5a67469625d52f2ef319cb2f5f3 100644 (file)
@@ -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() {
index 847d3a448cfd96b8e94dc932d6daa20caca88ca5..fbfa7d1d8a32bcec8ce2cabb109e23ad60571e44 100644 (file)
@@ -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;
                                                }
                                        }
index cf70d5c1a605320c5a2096d0fa244bafb0a63c10..a0454812a1ed4397ea00b7381623f366e6f6b260 100644 (file)
@@ -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 (file)
index 0000000..a943fa7
--- /dev/null
@@ -0,0 +1,7 @@
+define( [
+       "./arr"
+], function( arr ) {
+       "use strict";
+
+       return arr.sort;
+} );