Furthering the answer to this question Failure to override Element's addEventListener in Firefox
I don't want to use external wrapper/utility function mentioned in here. Javascript add events cross-browser function implementation: use attachEvent/addEventListener vs inline events
Objective: I simply call the overridden addEventListener function to keep things simple and it should handle the cross browser differences within itself or please advise.
I've edited the code, how can we achieve the cross browser functionality within this solution
(function() {
var interfaces = [ HTMLDivElement, HTMLImageElement /* ... (add as many as needed) */ ];
for (var i = 0; i < interfaces.length; i++) {
(function(original) {
interfaces[i].prototype.addEventListener = function(type, listener, useCapture) {
// DO SOMETHING HERE
if(element.attachEvent){ //IE
arguments[0] = 'on' + arguments[0];
return element.attachEvent.apply(this, arguments);
} else { //other browsers
return original.apply(this, arguments);
}
}
})(interfaces[i].prototype.addEventListener);
}
})();