0

I have a JavaScript class where I'd like to have a mutation observer to check when some nodes are added to a div. So in my constructor, I have something like this :

class MyClass{
    constructor(){
        this.prop1 = "stuff";
        this.prop2 = 18;
        this._myObserver = new MutationObserver(function(mutations){
            if (mutations[0].addedNodes.length > 0){
               //do some stuff
            }
        });
    }

    myMethod(){
        //do stuff
        this._myObserver.observe(myNode, myParameters)
        //do stuff
    }
}

The goal here is to display (for the sake of the example) the content of this.prop1 and calculate things with this.prop2 when I add subnodes to myNode.

How can I access the other properties of my object within that callback function?

sachaandre
  • 21
  • 2

0 Answers0