Skip to content

Instantly share code, notes, and snippets.

@tivac
Created September 15, 2009 17:26
Show Gist options
  • Save tivac/187468 to your computer and use it in GitHub Desktop.
Save tivac/187468 to your computer and use it in GitHub Desktop.
//Assume all code is wrapped within each respective library's DOMReady handler
//Scope-corrected callback in YUI 2
YAHOO.util.Event("id", "click", function(e) {
this._methodName();
}, null, this);
//Scope-corrected callback in YUI 3
Y.on("click", function(e) {
this._methodName();
}, "#id", this);
//Scope-corrected callback in jQuery 1.3.0
var that = this;
var cb = function(e) {
this._methodName();
}
$("#id").click(function(e) { cb.call(this, e); }))
//Scope-corrected callback in jQuery 1.3.0 using hitch plugin
$("#id").click($.hitch(this, function(e) {
this._methodName();
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment