Created
March 22, 2012 12:59
-
-
Save SeanJA/2158219 to your computer and use it in GitHub Desktop.
jquery.proxy.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if(typeof jQuery.proxy === 'undefined'){ | |
| jQuery.extend({ | |
| proxy : function( fn, proxy, thisObject ) { | |
| if ( arguments.length === 2 ) { | |
| if ( typeof proxy === "string" ) { | |
| thisObject = fn; | |
| fn = thisObject[ proxy ]; | |
| proxy = undefined; | |
| } else if ( proxy && !jQuery.isFunction( proxy ) ) { | |
| thisObject = proxy; | |
| proxy = undefined; | |
| } | |
| } | |
| if ( !proxy && fn ) { | |
| proxy = function() { | |
| return fn.apply( thisObject || this, arguments ); | |
| }; | |
| } | |
| // Set the guid of unique handler to the same of original handler, so it can be removed | |
| if ( fn ) { | |
| proxy.guid = fn.guid = fn.guid || proxy.guid || jQuery.guid++; | |
| } | |
| // So proxy can be declared as an argument | |
| return proxy; | |
| } | |
| }); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Created to accommodate the fact that jquery 1.3.2 does not have $.proxy so I could use this https://github.com/GBKS/Wookmark-jQuery