Last active
February 9, 2023 16:54
-
-
Save dmnsgn/4a6ad76de1b5928f13f68f406c70bb09 to your computer and use it in GitHub Desktop.
Revisions
-
dmnsgn revised this gist
Apr 16, 2016 . 1 changed file with 0 additions and 1 deletion.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 @@ -39,4 +39,3 @@ console.log(SingletonDefaultExportInstance.type); // Static method console.log(SingletonDefaultExportInstance.constructor.staticMethod()); -
dmnsgn created this gist
Apr 16, 2016 .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,42 @@ class SingletonDefaultExportInstance { constructor() { this._type = 'SingletonDefaultExportInstance'; } singletonMethod() { return 'singletonMethod'; } static staticMethod() { return 'staticMethod'; } get type() { return this._type; } set type(value) { this._type = value; } } export default new SingletonDefaultExportInstance(); // ... // index.js import SingletonDefaultExportInstance from './SingletonDefaultExportInstance'; // Instantiate // console.log(new SingletonDefaultExportInstance); // is not a constructor // Prototype Method console.log(SingletonDefaultExportInstance.type, SingletonDefaultExportInstance.singletonMethod()); // Getter/Setter SingletonDefaultExportInstance.type = 'type updated'; console.log(SingletonDefaultExportInstance.type); // Static method console.log(SingletonDefaultExportInstance.constructor.staticMethod()); // console.log(const instance = SingletonDefaultExportInstance.constructor);