I'd be surprised if it worked at all. It's syntactically correct, but will call the function straight away, then assign its return value to the onmousedown property. foo is a function; foo() is the return value of foo.
You can do something similar to this by using an inline function:
Code:
function foo(event) {
alert(event.clientX);
}
some_element.onmousedown = function(e) {
foo(e || window.event);
};
... but this is less efficient than the traditional approach:
Code:
function foo(e) {
var ev = e || window.event;
alert(ev.clientX);
}
some_element.onmousedown = foo;
Bookmarks