JavaScript removeEventlistener callback with argument

Viewed 121

Currently I'm trying to do like this:

el.addEventListener('scroll', callFunc);

el.removeEventListener('scroll', callFunc);

But with callback function which has parameters

el.addEventListener('scroll', () => callFunc(pr1, pr2));

el.removeEventListener('scroll', () => callFunc(pr1, pr2));

Is it possible to remove eventListener callback funcion with parameters?

1 Answers
  1. Create function with bounded arguments:
const func = callFunc.bind(null, pr1, pr2);
  1. Pass created function to addEventListener and removeEventListener.
Related