saintseiya
04-25-2007, 05:20 PM
Hey, thanks in advance to anyone who offers any kind of explanation to my question :)
I have this piece of code:
function listen(event, elem, func) {
if (elem.addEventListener) // W3C DOM
elem.addEventListener(event,func,false);
else if (elem.attachEvent) // IE DOM
elem.attachEvent('on'+event, function(){ func(new W3CDOM_Event(elem)) } );
// for IE we use a wrapper function that passes in a simplified faux Event object.
else throw 'cannot add event listener';
}
function W3CDOM_Event(currentTarget) {
this.currentTarget = currentTarget;
this.preventDefault = function() { window.event.returnValue = false }
return this;
}
I dont understand why for IE it needs to call the W3CDOM_Event function instead of just putting the event as the second parameter.
Any help appreciated, thanks :)
I have this piece of code:
function listen(event, elem, func) {
if (elem.addEventListener) // W3C DOM
elem.addEventListener(event,func,false);
else if (elem.attachEvent) // IE DOM
elem.attachEvent('on'+event, function(){ func(new W3CDOM_Event(elem)) } );
// for IE we use a wrapper function that passes in a simplified faux Event object.
else throw 'cannot add event listener';
}
function W3CDOM_Event(currentTarget) {
this.currentTarget = currentTarget;
this.preventDefault = function() { window.event.returnValue = false }
return this;
}
I dont understand why for IE it needs to call the W3CDOM_Event function instead of just putting the event as the second parameter.
Any help appreciated, thanks :)