If you aren't passing arguments to bindAsEventListener like,
Grid ={
otherMethod: function() {
//...
},
handler: function(arg1, arg2, arg3) {
this.otherMethod(arg2)
//...
}
};
$(document.body).observe('click',
Grid.handler.bindAsEventListener(Grid, "edit", "admin"));
// --> when document.body is clicked it will call the handler method
bound to Grid,
// so "this" is Grid, and pass the event object as arg1, "edit" as
arg2, and "admin" as arg3.
If your code looks like:
$(document.body).observe('click',
Grid.handler.bindAsEventListener(Grid));
// then you can totally use "bind" instead of "bindAsEventListener".
By default, in Prototype 1.6+ and jQuery, "this" of an event handler
is the element that you are observing.
In my previous examples it would be document.body. However using bind
I made "this" reference the Grid object.
AFAIK There isn't an equiv in jQuery, but then again the need is
pretty edge case.
http://www.prototypejs.org/api/function/bindAsEventListener
http://docs.jquery.com/Events/bind
- JDD