Menu
I’m trying to encapsulate some code in a class, but I can’t access the ‘this’ object from within an event handler, since ‘this’ has the event target in it.
[code]
function MyClass() {
this.foobar=”hello”;
this.create=function() {
var newSpan=document.createElement(‘span’);
newSpan.innerHTML=’sometext’;
newSpan.onmouseup=this.SPANonmouseup;
document.body.appendChild(newSpan);
}
this.SPANonmouseup=function (e) {
alert(this.foobar);
alert(this);
}
}
The first box reads ‘undefined’, the second reads ‘[object HTMLSpanElement]’. How can I access the class variables from an encapsulated event handler?