Skip to content

Instantly share code, notes, and snippets.

@DoRightt
Created June 6, 2020 16:54
Show Gist options
  • Save DoRightt/0f483c6b523a87d02551efb2cfd02cde to your computer and use it in GitHub Desktop.
Save DoRightt/0f483c6b523a87d02551efb2cfd02cde to your computer and use it in GitHub Desktop.
class Singletone {
private uniqueInstance: Singletone;
name = "vasya";
private constructor() {}
public static getInstance() {
if (this.uniqueInstance === undefined) {
this.uniqueInstance = new Singletone();
}
return this.uniqueInstance;
}
setName(name: string) {
this.name = name;
}
getName() {
return this.name;
}
}
let test1 = Singletone.getInstance();
test1.setName("petya");
console.log(test1.getName());
let test2 = Singletone.getInstance();
console.log(test2.getName());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment