Function.bindAsEventListener

Official docs: Function.bindAsEventListener

There's a misconception that any time you want to bind an event handler, you use bindAsEventListener. You don't. In fact, it's quite rare to need to use bindAsEventListener, usually you want to use bind. The only time you need to use bindAsEventListener is when you need to pass hardcoded parameters to your event handler: bindAsEventListener handles the fact that the first parameter is always the event in Prototype event handlers, and puts any additional hardcoded parameters you want bound to the function after the event parameter.

Example:

Event.observe('myDiv', 'click', this.myHandler.bindAsEventListener(this, 'a', 'b', 'c'));
// ...
function myHandler(evt, x, y, z)
{
    // Not only is 'this' correctly set, but evt is the event, and x = "a", y = "b", and z = "c"
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License