Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

ts Singleton pattern

class Singleton {
  private static instance: Singleton;

  private constructor() {}

  public static getInstance(): Singleton {
    if (!Singleton.instance) {
      Singleton.instance = new Singleton();
    }
    return Singleton.instance;
  }
}

const singleton = Singleton.getInstance();
Source by dev.to #
 
PREVIOUS NEXT
Tagged: #ts #Singleton #pattern
ADD COMMENT
Topic
Name
3+4 =