So I have a class declaration and in my constructor I want to add an event listener when the window scrolls. Something like this:
class MyClass {
constructor(el, options) {
// (...) initiating this properties and methods
$window.on('scroll', this.onScroll);
}
When I add my event listener I lose the this
scope (onScroll() creates its own this
instance), but if I use $window.on('scroll', () => this.scroll());
I keep my this
scope. Is there a way to keep my scope and not using the arrow function?