Created
May 25, 2022 13:22
-
-
Save HenriqueSilverio/8039fce2d66aaadeb9bb8968d0aebe73 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
class Registry { | |
private static instance: Registry | |
private constructor() {} | |
protected list = [] | |
private static getInstance() { | |
if (!Registry.instance) { | |
Registry.instance = new Registry() | |
} | |
return Registry.instance | |
} | |
public static getList(): Array<string> { | |
return Registry.getInstance().list | |
} | |
} | |
let a = Registry.getList() | |
let b = Registry.getList() | |
console.log(a === b) | |
a.push('foo') | |
console.log(a, b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment