Skip to content

Instantly share code, notes, and snippets.

@noherczeg
Last active March 22, 2016 15:27
Show Gist options
  • Select an option

  • Save noherczeg/2db1400ea4445c891286 to your computer and use it in GitHub Desktop.

Select an option

Save noherczeg/2db1400ea4445c891286 to your computer and use it in GitHub Desktop.
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());
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