Created
August 16, 2022 23:58
-
-
Save szaranger/f2923765914106a883ba187b2054818a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const element = document.getElementById('button'); | |
function onClick(event) { | |
element.innerHtml = 'text'; | |
} | |
element.addEventListener('click', onClick); | |
// Do stuff | |
// ... | |
// Remove handlers | |
element.removeEventListener('click', onClick); | |
element.parentNode.removeChild(element); | |
// Now when element goes out of scope, both element and | |
// onClick will be collected even in old browsers that | |
// don't handle cycles well. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment