'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.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source