JSFiddle - React, Tailwind, and code Playground

by Vladymyr Shevchuk

JavaScript

class Singleton {
	constructor () {
  	// if (!(this instanceof Singleton)) {
	  	//return new Singleton();      
    // }
    
    if (this.instance) {
    		return this.instance;
   	}
      
    const instance = Symbol('instance');
    this[instance] = this;
  }
}

const obj1 = new Singleton();
const obj2 = new Singleton();

console.log(obj1);