Skip to content

Instantly share code, notes, and snippets.

@amjedomar
Last active August 12, 2022 11:13
Show Gist options
  • Select an option

  • Save amjedomar/ad6b8230edfaf38badf7000dffc58cfa to your computer and use it in GitHub Desktop.

Select an option

Save amjedomar/ad6b8230edfaf38badf7000dffc58cfa to your computer and use it in GitHub Desktop.

Revisions

  1. amjedomar revised this gist Aug 12, 2022. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions static-and-non-static.ts
    Original file line number Diff line number Diff line change
    @@ -15,10 +15,10 @@ class Cat {
    }

    // access instance properties and methods
    const cat = new Cat('Milo');
    const milo = new Cat('Milo');

    console.log(cat.name);
    console.log(cat.getName());
    console.log(milo.name);
    console.log(milo.getName());

    // access static properties and methods
    console.log(Cat.count);
  2. amjedomar created this gist Aug 12, 2022.
    25 changes: 25 additions & 0 deletions static-and-non-static.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    class Cat {
    static count = 0;

    constructor(public name: string) {
    Cat.count++;
    }

    getName() {
    return this.name;
    }

    static getCount() {
    return this.count;
    }
    }

    // access instance properties and methods
    const cat = new Cat('Milo');

    console.log(cat.name);
    console.log(cat.getName());

    // access static properties and methods
    console.log(Cat.count);
    console.log(Cat.getCount());