Skip to content

Instantly share code, notes, and snippets.

@inomdzhon
Last active November 12, 2019 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inomdzhon/dc56ef84c0e752f940bd2452040d6608 to your computer and use it in GitHub Desktop.
Save inomdzhon/dc56ef84c0e752f940bd2452040d6608 to your computer and use it in GitHub Desktop.
// TODO check to `passive` param
function clearEventListener(target) {
var listeners = getEventListeners(target);
for (const key in listeners) {
if (!listeners.hasOwnProperty(key)) {
continue;
}
if (target[`on${key}`]) {
target[`on${key}`] = null;
continue;
}
for (let i = 0; i < listeners[key].length; i += 1) {
const item = listeners[key][i];
target.removeEventListener(key, item.listener, item.useCapture);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment