Skip to content

Commit 5336ff5

Browse files
committed
Core: Don't reimplement deprecated but not removed APIs
This will save space and avoid potential divergence from Core. To minimize risk, this only handles APIs still present in jQuery 4.x.
1 parent 95fd84d commit 5336ff5

File tree

2 files changed

+15
-53
lines changed

2 files changed

+15
-53
lines changed

src/jquery/core.js

+3-32
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import { jQueryVersionSince } from "../compareVersions.js";
22
import { migratePatchAndWarnFunc } from "../main.js";
33
import "../disablePatches.js";
44

5-
var arr = [],
6-
slice = arr.slice,
7-
class2type = {},
5+
var class2type = {},
86

97
// Require that the "whitespace run" starts from a non-whitespace
108
// to avoid O(N^2) behavior when the engine would try matching "\s+$" at each space position.
@@ -116,34 +114,7 @@ if ( jQueryVersionSince( "3.3.0" ) ) {
116114
// arguments.
117115
// jQuery.proxy is deprecated to promote standards (specifically Function#bind)
118116
// However, it is not slated for removal any time soon
119-
migratePatchAndWarnFunc( jQuery, "proxy",
120-
function( fn, context ) {
121-
var tmp, args, proxy;
122-
123-
if ( typeof context === "string" ) {
124-
tmp = fn[ context ];
125-
context = fn;
126-
fn = tmp;
127-
}
128-
129-
// Quick check to determine if target is callable, in the spec
130-
// this throws a TypeError, but we will just return undefined.
131-
if ( !isFunction( fn ) ) {
132-
return undefined;
133-
}
134-
135-
// Simulated bind
136-
args = slice.call( arguments, 2 );
137-
proxy = function() {
138-
return fn.apply( context || this, args.concat( slice.call( arguments ) ) );
139-
};
140-
141-
// Set the guid of unique handler to the same of original handler, so it can be removed
142-
proxy.guid = fn.guid = fn.guid || jQuery.guid++;
143-
144-
return proxy;
145-
}, "proxy",
146-
"jQuery.proxy() is deprecated"
147-
);
117+
migratePatchAndWarnFunc( jQuery, "proxy", jQuery.proxy,
118+
"proxy", "DEPRECATED: jQuery.proxy()" );
148119

149120
}

src/jquery/event.js

+12-21
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,9 @@ jQuery.each( ( "blur focus focusin focusout resize scroll click dblclick " +
9696
function( _i, name ) {
9797

9898
// Handle event binding
99-
migratePatchAndWarnFunc( jQuery.fn, name, function( data, fn ) {
100-
return arguments.length > 0 ?
101-
this.on( name, null, data, fn ) :
102-
this.trigger( name );
103-
},
104-
"shorthand-deprecated-v3",
105-
"jQuery.fn." + name + "() event shorthand is deprecated" );
99+
migratePatchAndWarnFunc( jQuery.fn, name, jQuery.fn[ name ], "shorthand-deprecated-v3",
100+
"DEPRECATED: jQuery.fn." + name + "() event shorthand" );
101+
106102
} );
107103

108104
// Trigger "ready" event only once, on document ready
@@ -118,20 +114,15 @@ jQuery.event.special.ready = {
118114
}
119115
};
120116

121-
migratePatchAndWarnFunc( jQuery.fn, "bind", function( types, data, fn ) {
122-
return this.on( types, null, data, fn );
123-
}, "pre-on-methods", "jQuery.fn.bind() is deprecated" );
124-
migratePatchAndWarnFunc( jQuery.fn, "unbind", function( types, fn ) {
125-
return this.off( types, null, fn );
126-
}, "pre-on-methods", "jQuery.fn.unbind() is deprecated" );
127-
migratePatchAndWarnFunc( jQuery.fn, "delegate", function( selector, types, data, fn ) {
128-
return this.on( types, selector, data, fn );
129-
}, "pre-on-methods", "jQuery.fn.delegate() is deprecated" );
130-
migratePatchAndWarnFunc( jQuery.fn, "undelegate", function( selector, types, fn ) {
131-
return arguments.length === 1 ?
132-
this.off( selector, "**" ) :
133-
this.off( types, selector || "**", fn );
134-
}, "pre-on-methods", "jQuery.fn.undelegate() is deprecated" );
117+
migratePatchAndWarnFunc( jQuery.fn, "bind", jQuery.fn.bind,
118+
"pre-on-methods", "jQuery.fn.bind() is deprecated" );
119+
migratePatchAndWarnFunc( jQuery.fn, "unbind", jQuery.fn.unbind,
120+
"pre-on-methods", "jQuery.fn.unbind() is deprecated" );
121+
migratePatchAndWarnFunc( jQuery.fn, "delegate", jQuery.fn.delegate,
122+
"pre-on-methods", "jQuery.fn.delegate() is deprecated" );
123+
migratePatchAndWarnFunc( jQuery.fn, "undelegate", jQuery.fn.undelegate,
124+
"pre-on-methods", "jQuery.fn.undelegate() is deprecated" );
125+
135126
migratePatchAndWarnFunc( jQuery.fn, "hover", function( fnOver, fnOut ) {
136127
return this.on( "mouseenter", fnOver ).on( "mouseleave", fnOut || fnOver );
137128
}, "pre-on-methods", "jQuery.fn.hover() is deprecated" );

0 commit comments

Comments
 (0)