Categories:
Partners

document.capture

Anyone familiar with NS and events should already know how to do this one:

document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=function(event) {
alert(event.type) // "mousedown"
}

If you don't feel like passing an argument, once again:

document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=function() {
alert(arguments[0].type) // "mousedown"
}

As is apparent, NS force feeds the event object as an argument, whether you want it or not. Unlike the previous examples of using arguments.callee.caller, no wrapper function is involved here. Nice and simple.

addEventListener

This only applies to NS6 and other Gecko-based browsers, such as Mozilla, K-meleon, and Galeon.

document.addEventListener('mousedown',doSomething,false);

The event is passed exactly the same as with captureEvents:

function doSomething(event) {
alert(event.type) // "mousedown"
}

Is the same as:

function doSomething() {
alert(arguments[0].type) // "mousedown"
}

Once again, no wrapper function involved, and the event argument is passed on, like it or not.