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

117
Visualizações
JavaScript class is undefined shortly after declaration

I have a class in my project called Floor. Theoretically, the class is defined, and I can successfully create an instance of it. However, 48 lines later, both class and instance are undefined. There are no delete statements or the like in those lines. I can reproduce this problem in Firefox, Chromium (Brave), and WebKit (Epiphany).

Code (abridged):

class Floor extends Entity {
    constructor(position = 700){
        super('floor');
        const transform = new Transform2D(0, position);
        this.attach(transform);
        this.attach(new class extends Component {
            canUse(system) {
                return system instanceof RenderSystem2D;
            }
            update(system) {
                system.ctx.beginPath();
                system.ctx.moveTo(transform.x, transform.actY);
                system.ctx.lineTo(640, transform.actY);
                system.ctx.strokeStyle = "red";
                system.ctx.stroke();
                console.log(system.game);
                for (let entity of system.game?.getWhere(e => e.hasComponent(Transform2D)            
                                                           && !e.hasComponent(Camera2D)
                                                           && e.getComponent(Transform2D).y > transform.y
                ) ?? []) {
                    system.game?.remove(entity);
                }
            }
            init(_system) {}
        });
    }
}
const fl = new Floor; // `fl` has been successfully constructed, and is a `Floor`.
// ...
// Both `fl` and `Floor` get deleted somewhere in the following two lines:
const tilemap = await platinum.image.load('tilemap.png');
const tileBitmap = await createImageBitmap(tilemap, 0, 0, 32, 32);
// ...
scene.add(fl); // both `fl` and `Floor` are undefined here; why?

One thing that may be of interest is that all of the lines in the definition of Floor are greyed out in the debugger; does that mean that they've been optimized out by the VM? If so, why?

Thank you.

platinum is https://github.com/aleksrutins/platinum.

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