1

I am having some difficulties with JavaScript classes. I've defined the below class (simplified for this example) which I instanciate from my main JavaScript file.

class GlobeControls
{
    constructor()
    {
        this.x = 5;
        document.addEventListener('wheel', this.handleMouseEvent);        
    }

    handleMouseEvent(event)
    {
        console.log(this.x);
    }
}

When I move the scroll wheel, the handleMouseEvent function is called, but doesn't seem to be able to see the variable x. The console just displays undefined. If I call the handleMouseEvent function from the console, it displays 5 as expected.

Nick
  • 62
  • 8

0 Answers0