Skip to content

Instantly share code, notes, and snippets.

@SeanJA
Created March 22, 2012 12:59
Show Gist options
  • Select an option

  • Save SeanJA/2158219 to your computer and use it in GitHub Desktop.

Select an option

Save SeanJA/2158219 to your computer and use it in GitHub Desktop.
jquery.proxy.js
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;
}
});
}
@SeanJA
Copy link
Author

SeanJA commented Mar 23, 2012

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment