I have a button which, when pressed, should call a function which calls another function. this is inside a class.
class cat{
constructor(){
this.event_listener();
}
log_2(){
console.log("cat 2");
}
log_1(){
console.log("cat 1");
this.log_2();
}
event_listener(){
document.getElementById("cat_button").addEventListener("click", this.log_1);
}
}
let cat1 = new cat();
The first function, this.log_1(), is called when the button is pressed and outputs "cat 1" as expected, but then the error
this.log_2 is not a function
appears on the console, although log_2() is defined within the class. How can I structure this so that log_2() is recognised as a function?