Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

104
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!