It's not possible with your current implementation - every call of .bind
creates a new separate function, and you can only call removeEventListener
to remove a listener if the passed function is the same (===
) as the one passed to addEventListener
(just like .includes
for arrays, or .has
for Sets):
const fn = () => 'foo';
console.log(fn.bind(window) === fn.bind(window));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…