aboutsummaryrefslogtreecommitdiffstats
path: root/src/deprecated.js
diff options
context:
space:
mode:
authorTimmy Willison <4timmywil@gmail.com>2017-12-11 12:58:35 -0500
committerTimmy Willison <4timmywil@gmail.com>2018-01-08 11:28:35 -0500
commit3a8e44745c014871bc56e94d91e57c45ae4be208 (patch)
tree35bfd2a7dc382712bbc26a9076c4d865e09ae58f /src/deprecated.js
parent909e0c99251ee56ec35db0e08d5b1e6219ac8fbc (diff)
downloadjquery-3a8e44745c014871bc56e94d91e57c45ae4be208.tar.gz
jquery-3a8e44745c014871bc56e94d91e57c45ae4be208.zip
Core: deprecate jQuery.proxy (not slated for removal)
Fixes gh-2958 Close gh-3885
Diffstat (limited to 'src/deprecated.js')
-rw-r--r--src/deprecated.js36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/deprecated.js b/src/deprecated.js
index 74907a289..8523ee5b8 100644
--- a/src/deprecated.js
+++ b/src/deprecated.js
@@ -2,8 +2,9 @@ define( [
"./core",
"./core/nodeName",
"./core/camelCase",
- "./var/isWindow"
-], function( jQuery, nodeName, camelCase, isWindow ) {
+ "./var/isWindow",
+ "./var/slice"
+], function( jQuery, nodeName, camelCase, isWindow, slice ) {
"use strict";
@@ -28,6 +29,37 @@ jQuery.fn.extend( {
}
} );
+// Bind a function to a context, optionally partially applying any
+// arguments.
+// jQuery.proxy is deprecated to promote standards (specifically Function#bind)
+// However, it is not slated for removal any time soon
+jQuery.proxy = function( fn, context ) {
+ var tmp, args, proxy;
+
+ if ( typeof context === "string" ) {
+ tmp = fn[ context ];
+ context = fn;
+ fn = tmp;
+ }
+
+ // Quick check to determine if target is callable, in the spec
+ // this throws a TypeError, but we will just return undefined.
+ if ( !jQuery.isFunction( fn ) ) {
+ return undefined;
+ }
+
+ // Simulated bind
+ args = slice.call( arguments, 2 );
+ proxy = function() {
+ return fn.apply( context || this, args.concat( slice.call( arguments ) ) );
+ };
+
+ // Set the guid of unique handler to the same of original handler, so it can be removed
+ proxy.guid = fn.guid = fn.guid || jQuery.guid++;
+
+ return proxy;
+};
+
jQuery.holdReady = function( hold ) {
if ( hold ) {
jQuery.readyWait++;