Created
October 16, 2021 08:54
-
-
Save WesleySmits/316a870789e518da7eb2e72918ead517 to your computer and use it in GitHub Desktop.
Simple web calculator: Adding event bindings to calculator class
This file contains 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
protected connectedCallback(): void { | |
this.#setEventListeners(); | |
} | |
protected disconnectedCallback(): void { | |
this.#unsetEventListeners(); | |
} | |
#setEventListeners(): void { | |
this.#buttons.forEach((button) => { | |
button.addEventListener('click', this.#handleButtonClick.bind(this)); | |
}); | |
} | |
#unsetEventListeners(): void { | |
this.#buttons.forEach((button) => { | |
button.removeEventListener('click', this.#handleButtonClick.bind(this)); | |
}); | |
} | |
#handleButtonClick(event: Event): void { | |
// do something | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment