I am not a javascript object oriented pro and am stuck for a while now. I am trying to implement a call back api so that i can detect when an element is being scrolled. Unfortunately, am unable to fire the prototype method from another method. Please help
//HTML
//<div style="width:500px;height:500px;"id="myElement"></div>
//JS
mousewheelListen=function(){
this.el.addEventListener('wheel',);//How do i call Scroller.prototype.scrolling() ?
}
Scroller=function(el){//Constructor
this.el=el;
mousewheelListen.call(this);
}
Scroller.prototype.scrolling=function(callback){//
callback.call(this);
}
var el=document.getElementById('myElement');
var myScroller=new Scroller(el);
myScroller.scrolling(function(){//Listening when scrolling
console.log('scrolling');
});
this.el.addEventListener('wheel', event => this.scrolling(event))this.scrolling()an event object, not a callback function. If you want to pass in some sort of callback, you'll need to do that instead. I'm not exactly sure what you're trying to accomplish with this callback parameter.myScroller.scrolling()? This is where, I think, there's some logical issues in this code. What's this scrolling function supposed to do? Are you supposed to call it with a callback, with the expectation that the provided callback will be called every time this event fires? Or is this scrolling function itself supposed to be called everytime the event fires? Right now it seems your scrolling function is trying to do both of these things?