K
King Albert
Question :
Is it 'good design' to make an eventhandler a method of your class ?
Problem in the eventhandler below :
I need 'this' to refer to Tabel, not to the clicked element !
function Tabel(dataset, behavior) {
this.dataset=dataset;
this.behavior=behavior;
}
Tabel.prototype.generatetable() {
....
row = document.createElement("tr");
row.onclick=this.severalbehaviors;
....
}
Tabel.prototype.severalbehaviors(e) {
var el=e.currentTarget; //now el points to the clicked element
... //which is fine because I need the element
for (var veld in this.dataset[0][0]) { // but I also need to access
the dataset within the eventhandler
...
}
...
}
thx for any help,
Ward
Is it 'good design' to make an eventhandler a method of your class ?
Problem in the eventhandler below :
I need 'this' to refer to Tabel, not to the clicked element !
function Tabel(dataset, behavior) {
this.dataset=dataset;
this.behavior=behavior;
}
Tabel.prototype.generatetable() {
....
row = document.createElement("tr");
row.onclick=this.severalbehaviors;
....
}
Tabel.prototype.severalbehaviors(e) {
var el=e.currentTarget; //now el points to the clicked element
... //which is fine because I need the element
for (var veld in this.dataset[0][0]) { // but I also need to access
the dataset within the eventhandler
...
}
...
}
thx for any help,
Ward