I need to add new EventListener with help setInterval, but i can't remove old EventListener.
getEventListeners(document) to see, that document to add "mouseup", every 100ms
I not finded similar question
let tt = function() {
let qq = function() { console.log(1)}
document.removeEventListener('mouseup', qq, true);
document.addEventListener('mouseup', qq, true);
}
setInterval( tt, 100)
You redefine the qq function every time tt called, so it is a new object, and can not be matched on event listener removal process: matching event listeners for removal.
If we define function once with var, it works:
var qq = function() { console.log(1)}
let tt = function() {
document.removeEventListener('mouseup', qq, true);
document.addEventListener('mouseup', qq, true);
}
setInterval( tt, 100)