Use a closure. Whatever method this code is inside, add one line at the top of the method:
var self = this; Then, every place where you would use "this" in the method, use self instead: $(".button").bind("click", function(event) { self.handleEvent(); return false; }); When you do this, I suggest not using a mix of "self" and "this" in the method - change every "this" reference in the method to "self". I find it less confusing that way. You can use "that" or any name you like instead of "self", of course. The nice thing about the closure is that it always works, regardless of the particular JavaScript library or framework you may be using. -Mike > From: [EMAIL PROTECTED] > > I'm not sure if I've completely missed this in the docs, but > I'm wondering if there is an easier way of achieving the following: > > $(".button").bind("click", {that:this}, function(event) { > var that = event.data.that; > that.handleEvent(); > return false; > }); > > I could do the same thing in prototype using "bindAsEventListener" > like this: > > Event.observe($$(".button"), 'click', > this.handleEvent.bindAsEventListener(this)); > > This would help tidy everything up a lot, since I'd like to > maintain a class-based pattern where "this" is used a lot. > Passing it in as event data seems like overkill. > > Thanks :) >