Last active
April 9, 2024 06:28
-
-
Save hevi1991/3dcee40f32c1b44f254f3a11712ab78f to your computer and use it in GitHub Desktop.
Revisions
-
hevi1991 revised this gist
Apr 9, 2024 . No changes.There are no files selected for viewing
-
hevi1991 revised this gist
Oct 30, 2023 . 2 changed files with 1 addition and 1 deletion.There are no files selected for viewing
File renamed without changes.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 @@ -1,4 +1,4 @@ import Video from "./singletonClass.js"; const v2 = new Video(`v2`); const v = new Video(`v`); -
hevi1991 created this gist
Oct 30, 2023 .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,13 @@ import { singleton } from "./singleton.js"; class Video { constructor(name) { this.name = name; } play() { console.log(`${this.name} is playing`); } } export default singleton(Video); 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,14 @@ export function singleton(clazz) { let instance; return new Proxy(clazz, { construct(target, args) { if (instance) { return instance; } else { instance = new target(...args); return instance; } }, }); } 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,8 @@ import Video from "./exampleClass.js"; const v2 = new Video(`v2`); const v = new Video(`v`); v.play(); v2.play(); console.log(v === v2);