In the classroom to hang and remove EventListner's?

Wrote your own plugin for scrolling page (tipo fullPage.js)
in a functional style written, all worked fine
Then I started to solve the problem "and how to connect this library?" was rewritten in OOP, made a class to this class to import main.js and there already .init()
But faced this:
when I initiate the kick from the event on the window:
window.addEventListener("mousewheel", this.onWheel.bind(this))

(Yes, I know that it is possible to use the pointer methods instead .bind(this), but I somehow babel-polyfill does not connect, don't really want it now to mess around)
then, when this event fires - I delete it:
window.removeEventListener("mousewheel", this.onWheel.bind(this));

and after 600 MS. hang back:
setTimeout(() => {window.addEventListener("mousewheel", this.onWheel.bind(this))}, 600);

(about 600мс lasts animation scrolling to the desired block)
And that's actually what the problem is: the event is now suspended, but not deleted. How to be? What to do?
March 19th 20 at 08:54
1 answer
March 19th 20 at 08:56
Solution
You should be aware that

this.onWheel.bind(this) !== this.onWheel.bind(this)

Save somewhere created the handler when adding and deleting a pass removeEventListener him, not a new feature.
And it is possible an example? and I do not quite understand what it means to "save handler") - Claudine_Boyle commented on March 19th 20 at 08:59
@Claudine_Boyle,
let onwheel = this.onWheel.bind(this);
and pass onwheel in addEventListener/removeEventListener - Wade37 commented on March 19th 20 at 09:02
@Claudine_Boyle, example can. - esthe commented on March 19th 20 at 09:05
@Wade37, exactly) I was confused that I called the function "onwheel" and it looked now as "onclick" and similar listeners)) sick-_-
somehow I just did not think to do so)
thank you - Claudine_Boyle commented on March 19th 20 at 09:08
@Wade37, @esthe, googled some more, it turns out, it is possible to hang an event in such a way that it would work 1 time and disappear :
window.addEventListener("wheel", this.onWheel.bind(this), {
once: true
})

and it is not necessary now to remove this event - Claudine_Boyle commented on March 19th 20 at 09:11

Find more questions by tags JavaScript