I use to ecma6. I have problem with access to method in class, when I use onclick. I would like to induce method, which can induce other method in class.
This works:
class Menu{
nextIteration(){...}
init(){
var that = this;
//...
buttonStart.onclick = function () {
if(!that._start) {
//...
that.nextIteration();
} else if(that._start && that._pause) {
//..
that.nextIteration();
}
};
}
}
Now I tried:
class Menu{
nextIteration(){...}
init(){
//...
buttonStart.onclick= clickStart;
}
//...
clickStart(){
var that = this;
if(!that._start) {
//...
that.nextIteration();
} else if(that._start && that._pause) {
//...
that.nextIteration();
}
}
}
In my opinion event is not beautiful. I prefer induce method in class. I tried addEventListener and "this" refer to element DOM.