Robert wrote:
Hi,
The problem only occurs after I have defined the srcElement.
So if I have executed the following code:
Event.prototype .__defineGetter __("srcElement" , function()
{
var node = this.target;
while (node.nodeType != 1)
node = node.parentNode ;
return node;
});
And later I do
if (Event.prototyp e.srcElement)
I will get the exception :(
That's quite normal, you've actually just defined a getter for
Event.prototype , and then you *call* it in the "if" structure while you
should just check its existence; as a result, in the call, "this" refers
to the prototype itself, not any event, and calling the getter defined
for "target" in such a context makes it fail.
Be more defensive, with the srcElement getter
Event.prototype .__defineGetter __(
"srcElement ",
function() {
var node=null;
if(this.constru ctor==Event) {
node = this.target;
while (node && node.nodeType != 1)
node = node.parentNode ;
}
return node;
}
);
and with the way you infer the existence of a property
function isUndefined(obj , prop){
var isUndefined=tru e;
if(obj.__lookup Getter__){
if(typeof obj.__lookupGet ter__(prop)!="u ndefined") {
isUndefined=fal se;
}
}
if(isUndefined) {
isUndefined=(ty peof obj[prop]=="undefined" );
}
return isUndefined;
}
HTH,
Yep.