This brings in a lot of unnecessary clutter that is needed to create singletons in OO programming languages with namespaces and classes.
This is a singleton in JavaScript (assuming global scope):
const ProcessManager = {
numProcess: 0,
increment() {
this.numProcess++
}
}
Now I'm not saying it cannot be done that way, but having this implementation is more true to the nature of JavaScript.
Even then... most modern JS is written in modules (cjs or esm)...
//module singleton...
let numProcess = 0;
export default { // or module.exports for cjs
increment: () => numProcess++,
};
Can still have the internal numProcess private.
This is a very good addition recognising the implicit module environment we're all most probably working in (leveraging tools like Webpack, etc.), thank you for sharing this!