Here's the thing. I looked up a pong game for java and now I want to try to make it in js. I'm still not good at js and I'm trying to code a simple pong game while trying to use classes like in java. But the problem is I always get this error "Uncaught TypeError: Cannot read properties of undefined (reading 'move')". I've tried looking online for solutions but I still don't get it. This also shows up for the other two methods, draw and run. Can anyone please kindly tell me why this happens?
class Game {
constructor() {
this.run();
}
run() {
this.move();
this.draw(ctx);
requestAnimationFrame(this.run);
}
draw(ctx) {
paddle.draw(ctx);
}
move() {
paddle.move();
}
}
let game = new Game();
Thank you very much in advance to anyone who will answer this.
In this case, you call to the method of instancepaddle and it's not declare yet.
That's why, javascript cheat as paddle undefine variable.