Last active
March 22, 2016 15:27
-
-
Save noherczeg/2db1400ea4445c891286 to your computer and use it in GitHub Desktop.
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 characters
| var Singleton = (function () { | |
| function Singleton() { | |
| this.asd = 'SSSSSS'; | |
| } | |
| Singleton.prototype.Singleton = function () { }; | |
| Singleton.getInstance = function () { | |
| return Singleton.INSTANCE; | |
| }; | |
| Singleton.prototype.sayWhat = function (attr) { | |
| return attr; | |
| }; | |
| Singleton.prototype.getAsd = function () { | |
| return this.asd; | |
| }; | |
| Singleton.INSTANCE = new Singleton(); | |
| return Singleton; | |
| }()); | |
| var x1 = Singleton.getInstance().sayWhat('whhhhaaat?!?!'); | |
| var x2 = Singleton.getInstance(); | |
| console.log(x2.getAsd()); |
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 characters
| class Singleton { | |
| private static INSTANCE:Singleton = new Singleton(); | |
| private asd: string = 'SSSSSS'; | |
| private Singleton() {} | |
| public static getInstance():Singleton { | |
| return Singleton.INSTANCE; | |
| } | |
| public sayWhat(attr: String):String { | |
| return attr; | |
| } | |
| public getAsd():String { | |
| return this.asd; | |
| } | |
| } | |
| var x1 = Singleton.getInstance().sayWhat('whhhhaaat?!?!'); | |
| var x2 = Singleton.getInstance(); | |
| console.log(x2.getAsd()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment