DEV Community

loading...

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
aakatev profile image
Artem Author

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