Last active
August 3, 2022 15:54
-
-
Save mohammadhb/a9d52562fae63e722adea13c6e9d32eb to your computer and use it in GitHub Desktop.
Revisions
-
mohammadhb revised this gist
Aug 3, 2022 . 1 changed file with 22 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ //Works with new class Counter { static instance; constructor(x){ this.x = x if(!Counter.instance) Counter.instance = this; return Counter.instance; } counter = 0; getCount() { return this.counter; } increment() { this.counter = this.counter + 1; return this.counter; } } module.exports = Counter; -
mohammadhb created this gist
Aug 3, 2022 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ class Counter { static instance; static getInstance(){ if(!Counter.instance) Counter.instance = new Counter(); return Counter.instance; } counter = 0; getCount() { return this.counter; } increment() { this.counter = this.counter + 1; return this.counter; } } module.exports = Counter.getInstance();