Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

149
Visualizações
Reason for "Cannot read properties of undefined"

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.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

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.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda