DEV Community

Discussion on: Singleton Pattern in JavaScript

Collapse
 
halcika7 profile image
Haris Beslic

What about this approach?

class SomeClass {
constructor() {
if (!SomeClass.instance) {
SomeClass.instance = this;
}

return SomeClass.instance;

}
}

Collapse
 
hi_artem profile image
Artem

Yes, this is another way of doing it. More OOP way, I would say.