DEV Community


Discussion on: Singleton Pattern in Javascript

andi23rosca profile image
Andi Rosca • Edited

I agree. Singletons are less of a design pattern and more of a work-around for the limitation of languages that only let you use classes and nothing else.

And apart from some sense of "this must be readable because I'm using design patterns" I think most people will find

// Singleton.js
export const Singleton = { name: "John" };
// some other file
import { Singleton } from "...";
Enter fullscreen mode Exit fullscreen mode

way more readable than the 2 different files presented in the example, with so much ceremony around what you are actually trying to accomplish.

Forem Open with the Forem app