Skip to content

Instantly share code, notes, and snippets.

@WesleySmits
Created October 16, 2021 08:54
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 WesleySmits/316a870789e518da7eb2e72918ead517 to your computer and use it in GitHub Desktop.
Save WesleySmits/316a870789e518da7eb2e72918ead517 to your computer and use it in GitHub Desktop.
Simple web calculator: Adding event bindings to calculator class
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