Encountered a problem with using IntersectionObserver inside a class. For example, I am creating from my class constructor observer instance and create a callback - function in the current class. When the function executes "this" not points to my class instance, it points to Observer instance. I tried to use arrow functions and other ways, but didn't any results. Any ideas?
class SomeClass {
constructor(className) {
this.className = className;
this.element = document.getElementByID(this.className);
this.observer = new IntersectionObserver(this.someFunc, {threshold: 0.5});
this.observer.observe(this.element);
}
someFunc(entry) {
entry.forEach((change) => {
console.log(this.className);
});
}
}
someInstance = new SomeClass("some-class__element");