attachEvent !?
Hi everyone,
Consider this snippet:
var obj={
attribute:1,
documentClicked:function (){
alert(this.attribute);
}
}
document.attachEvent('onclick',obj.documentClicked );
When run on IE with page clicks this.attribute is undefined! With Firefox you will face the same issue while using addEventListener instead.
What can I do about it? It's really irritating to put attribute in global scope (window scope) and for some reasons I don't tend to do so at all. By putting onclick in <body> this issue is probably resolved but for some other reasons attachEvent is much better.
Best Regards
Nerssi
|