Created
June 6, 2020 16:54
-
-
Save DoRightt/0f483c6b523a87d02551efb2cfd02cde to your computer and use it in GitHub Desktop.
This file contains 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 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