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

347
Visualizações
Undefined: How do I reference this class method within a class properly?

I cant call the Circle class 'move' function from a function within a function

I have tried a couple of fixes like making functions that run the function I want, but that just resulted in the same problem.

I simplified things to make it easier to read

class Bullet
    {
        constructor()
        {
            this.bullet = new Circle(radius);
            // Circle class contains a function move(x,y);
        }

Calling this works tho

        setpos(x,y){
            this.bullet.move(x,y)
        }

This too

        moves(xmov, ymov, moveTime)
        {
            this.bullet.move(xmov,ymov);
            setpos(xmov,ymov); 
        }

this is fully working, but not what I want.

this version is what i think should work, but function is "undefined":

        moves(xmov, ymov, moveTime)
        {
            this.xmov = xmov; // assigning parameters to instance of object hopefully correctly
            this.ymov = ymov;
            this.moveTime = moveTime;
            
            // probably unnecessary but it didnt recognise it otherwise?
            var mt = this.moveTime;
            var xmv = this.xmov;
            var ymv = this.ymov;

            var timerCount = 0;

            setTimer(moveitman,1) //  <-- calls moveitman() every 1ms
            function moveitman() {

                timeCount++;

                if (timerCount < mt) {
                    var xSpeed = xmv / mt; //  < this stuff works
                    var ySpeed = ymv / mt;
                    
                    this.bullet.move(xSpeed,ySpeed); // undefined but worked outside the function???
                }
           }
about 4 years ago · Juan Pablo Isaza
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