The concept of a "singleton class" comes from languages that just have classes (Java for example), JavaScript however has much more than classes (objects, functions, "global code"), and therefore we don't need to mimic a singular object creation with a fake class, we can just do:
const singleton = { some: 0, properties: 0 };
// initialization goes here
You are right that it is possible to create a "singleton class", but that has no benefits, it just adds boilerplate, and, in my eyes, makes the code harder to follow (as I'd expect new Class
to create an instance, and not to return a singleton).
To check wether an instance comes from a class that is written in your "singleton pattern way", you could simply check for the instance:
instance === instance.constructor.instance
But I'm not sure wether that is useful at all. It's questionable wether you actually need those classes, and if you really need those, then you probably only have a few of them, and it would be way less error prone to check wether the instance is instanceof
one of them:
instance instanceof Singleton1 || instance instanceof Singleton2
If your "singleton class"es are not written by you, and you only know that they come from a constructor function that might return existing instances, then the only way would be to create a new instance of that class, and check wether the same instance was returned:
instance === new instance.constructor
If the constructor however requires arguments then that will break, or if it's just a regular class instance you will create an unneccessary instance, which might cause unwanted side effects.
So after all: Why do you need that?