HTMLElement.prototype.addEventListener = function()
{
alert('overridden');
};
HTMLElement.prototype.anotherMethod= function()
{
alert('anothermethod');
};
var div = document.createElement('div');
alert(div.anotherMethod.toString()); // alerts function ()
{ alert('anotherMethod'); }
alert(div.addEventListener.toString()); // alerts function() { [native
code ]};
Does anyone know if its possible to override a native method in
forefox ?
Marc
It is possible, by direct assignment, to ignore the existing method of a
host object (you cannot access objects directly, you can only use references
to them) but it is error-prone always. Forget about it and use a wrapper
method (maybe a property of a user-defined wrapper object) instead.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
I guess I will have to resort to something that Prototype does and
have an "observe"
method that wraps addEventListener. I was hoping to keep the W3C API
though :(
On Jul 23, 7:15 pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
I guess I will have to resort to something that Prototype does and
have an "observe"
method that wraps addEventListener. I was hoping to keep the W3C API
though :(
On Jul 23, 7:15 pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
Note that .addEventListener() is not on HTMLElement but on EventTarget
(a different interface that is implemented by all objects that implement
the Element interface). Whether that helps you with your problem I do
not know, I would rather second Thomas' advice.
The DOM Level 2 Events specification says "The EventTarget interface
is implemented by all Nodes in an implementation which supports the
DOM Event Model". So it is objects implementing the Node interface
that should implement the EventTarget.