XF 2.2 JS: remove event listener from document?

Newsman

Member
Hey there!

Say, I've got the following code:

JavaScript:
document.addEventListener('mouseup', XF.proxy(this, 'actionEnd'));

Using the XF.proxy (which if I remember correctly will be deprecated in the future), I bind the event to a function.

Now here's my question: how do I remove that event listener again? Using removeEventListener for example did not work for me..

JavaScript:
document.removeEventListener('mouseup', XF.proxy(this, 'actionEnd'));

Even replacing the XF.proxy bit with something like this.actionEnd() didn't work for me..

Thanks for any help!
 
XF.proxy will create a new bound function, but EventTarget.removeEventListener wants the same function. You can store the bound function in a variable to reuse it across calls:

JavaScript:
const actionEnd = XF.proxy(this, 'actionEnd');
document.addEventListener('mouseup', actionEnd);
document.removeEventListener('mouseup', actionEnd);
 
Back
Top Bottom