Skip to content

Instantly share code, notes, and snippets.

@HenriqueSilverio
Created May 25, 2022 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HenriqueSilverio/8039fce2d66aaadeb9bb8968d0aebe73 to your computer and use it in GitHub Desktop.
Save HenriqueSilverio/8039fce2d66aaadeb9bb8968d0aebe73 to your computer and use it in GitHub Desktop.
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