diff options
author | Timmy Willison <4timmywil@gmail.com> | 2017-12-11 12:58:35 -0500 |
---|---|---|
committer | Timmy Willison <4timmywil@gmail.com> | 2018-01-08 11:28:35 -0500 |
commit | 3a8e44745c014871bc56e94d91e57c45ae4be208 (patch) | |
tree | 35bfd2a7dc382712bbc26a9076c4d865e09ae58f /src | |
parent | 909e0c99251ee56ec35db0e08d5b1e6219ac8fbc (diff) | |
download | jquery-3a8e44745c014871bc56e94d91e57c45ae4be208.tar.gz jquery-3a8e44745c014871bc56e94d91e57c45ae4be208.zip |
Core: deprecate jQuery.proxy (not slated for removal)
Fixes gh-2958
Close gh-3885
Diffstat (limited to 'src')
-rw-r--r-- | src/core.js | 29 | ||||
-rw-r--r-- | src/deprecated.js | 36 | ||||
-rw-r--r-- | src/effects.js | 2 |
3 files changed, 35 insertions, 32 deletions
diff --git a/src/core.js b/src/core.js index 06d0e83ad..037e31740 100644 --- a/src/core.js +++ b/src/core.js @@ -395,35 +395,6 @@ jQuery.extend( { // A global GUID counter for objects guid: 1, - // Bind a function to a context, optionally partially applying any - // arguments. - 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.support is not used in Core but other projects attach their // properties to it so it needs to exist. support: support 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++; diff --git a/src/effects.js b/src/effects.js index ec82d59f6..514baaec8 100644 --- a/src/effects.js +++ b/src/effects.js @@ -387,7 +387,7 @@ function Animation( elem, properties, options ) { if ( result ) { if ( jQuery.isFunction( result.stop ) ) { jQuery._queueHooks( animation.elem, animation.opts.queue ).stop = - jQuery.proxy( result.stop, result ); + result.stop.bind( result ); } return result; } |