A
Andrew Poulos
I have some code that's structured a bit like this:
Con = function(choice, el) {
this.choice = choice;
document.getElementById(el).onclick = this.choiceClicked;
}
Con.prototype.choiceClicked = function() {
alert(this.choice);
}
foo = new Con(1,"bar")
Why is it when I click on the element "bar" this choice alerts as
'undefined'? In the prototype 'this' is the element clicked and not what
is was expecting (the object 'foo'). I'd like the 'this' in the
prototype to refer to 'foo': is there some way to do this?
Andrew Poulos
Con = function(choice, el) {
this.choice = choice;
document.getElementById(el).onclick = this.choiceClicked;
}
Con.prototype.choiceClicked = function() {
alert(this.choice);
}
foo = new Con(1,"bar")
Why is it when I click on the element "bar" this choice alerts as
'undefined'? In the prototype 'this' is the element clicked and not what
is was expecting (the object 'foo'). I'd like the 'this' in the
prototype to refer to 'foo': is there some way to do this?
Andrew Poulos