diff options
author | John Resig <jeresig@gmail.com> | 2011-04-17 14:11:40 -0700 |
---|---|---|
committer | timmywil <tim.willison@thisismedium.com> | 2011-04-17 18:17:31 -0400 |
commit | 15da298f72bf94a95563abc12b8e6fec8c604099 (patch) | |
tree | bd70c0fc5ce8d81e8aca9c9ae08cf071baacd403 /src/core.js | |
parent | 2a71493447b91731cfbcbd3cce18bbdb8949c96a (diff) | |
download | jquery-15da298f72bf94a95563abc12b8e6fec8c604099.tar.gz jquery-15da298f72bf94a95563abc12b8e6fec8c604099.zip |
Remove unnecessary usage of Function.prototype.bind (#7783) but maintain API. Also fix bug with proxy failing when a name is provided. Fixes #8893.
Diffstat (limited to 'src/core.js')
-rw-r--r-- | src/core.js | 40 |
1 files changed, 9 insertions, 31 deletions
diff --git a/src/core.js b/src/core.js index 89bbde5c0..a82a2fdce 100644 --- a/src/core.js +++ b/src/core.js @@ -752,45 +752,23 @@ jQuery.extend({ // Bind a function to a context, optionally partially applying any // arguments. proxy: function( fn, context ) { - var args, proxy; - - // XXX BACKCOMPAT: Support old string method. if ( typeof context === "string" ) { - fn = fn[ context ]; - context = arguments[0]; + var 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 ) ) { + if ( !jQuery.isFunction( fn ) ) { return undefined; } - if ( jQuery.support.nativeBind ) { - // Native bind - args = slice.call( arguments, 1 ); - if ( args.length ) { - proxy = Function.prototype.bind.apply( fn, args ); - } else { - proxy = fn.bind( context ); - } - } else { - // Simulated bind - args = slice.call( arguments, 2 ); - if ( args.length ) { - proxy = function() { - return arguments.length ? - fn.apply( context, args.concat( slice.call( arguments ) ) ) : - fn.apply( context, args ); - }; - } else { - proxy = function() { - return arguments.length ? - fn.apply( context, arguments ) : - fn.call( context ); - }; - } - } + // Simulated bind + var args = slice.call( arguments, 2 ), + proxy = function() { + return fn.apply( context, 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 || proxy.guid || jQuery.guid++; |