How do I add and remove an event listener using a function with parameters?

Have you tried maintaining a reference to the anonymous function (like you suggested)?

So:

var listener = function() {
  check_pos(box);
};

window.addEventListener('scroll', listener, false);
...
window.removeEventListener('scroll', listener, false);

Mozilla’s docs suggest the same thing.

Leave a Comment

tech