I want to access the variable ctx which is located in the constructor of my game and in the loop function which accesses it to clean the canvas I get the error "main.js: 191 Uncaught TypeError: Can not read property ' clearRect 'of undefined " code- >
class JuegoSnake {
constructor() {
this.comidas = [];
this.canv = document.getElementById("canvas");
this.puntuacion = 0;
this.ctx = this.canv.getContext("2d");
this.scl = 40;
this.canv.width = window.innerWidth;
this.canv.height = Math.floor(window.innerHeight * 1);
this.serpiente = new snake();
this.comidas.push(new comida(this.scl));
}
draw() {
this.ctx.clearRect(0, 0, this.canv.width, this.canv.height);
drawFondo(this.ctx);
}