Skip to content

Instantly share code, notes, and snippets.

@batazo
Created July 3, 2022 19:10
Show Gist options
  • Select an option

  • Save batazo/ccc9c990a90ce6776e123af1b9f081e8 to your computer and use it in GitHub Desktop.

Select an option

Save batazo/ccc9c990a90ce6776e123af1b9f081e8 to your computer and use it in GitHub Desktop.

Revisions

  1. batazo renamed this gist Jul 3, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. batazo created this gist Jul 3, 2022.
    25 changes: 25 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    class Banner extends HTMLElement {
    // Private variable that cannot be reached directly from outside, but can be modified by the methods inside:

    #slogan = "Hello there!"
    #counter = 0

    // private getters and setters (accessors):

    get #slogan() {return #slogan.toUpperCase()}
    set #slogan(text) {this.#slogan = text.trim()}

    get #counter() {return #counter}
    set #counter(value) {this.#counter = value}

    constructor() {
    super();
    this.onmouseover = this.#mouseover.bind(this);
    }

    // private method:
    #mouseover() {
    this.#counter = this.#counter++;
    this.#slogan = `Hello there! You've been here ${this.#counter} times.`
    }
    }