I usually program in Java and when I add an event listener to an attribute in a class, I can call the methods from the class inisde the event. However in JavaScript if I use "this." inside the function, the context is "onclick" and if I don't use "this." I get an error that resetear is not defined. How can I access the attributes and methods from Calculadora inside the onclickfunction?
class Calculadora{
constructor () {
this.resultado = document.getElementById("resultado");
this.c = document.getElementById("C");
...
this.memoria = "";
this.a = 0;
this.b = 0;
this.operacion = "";
}
resetear(){
this.resultado.textContent = "";
this.a = 0;
this.b = 0;
this.operacion = "";
}
assignar() {
this.c.onclick = function(e){ // Here I need to change some things about Calculadora
resultado.textContent = "";
this.a = 0;
this.b = 0;
this.operacion = "";
}
...
}
}