I am working on a large project where I have multiple managers to handle different tasks, I need an only a single object of these managers to be created when I start the app,
I came across this method of Singleton creation
class QuestionnaireManager {
constructor() {
if (this.instance) {
return;
}
this.instance = this;
}
}
Is this an acceptable way, is there any downside, I am coming from JAVA
Kotlin
background and this seems to simple to be true where we have so much to deal in case of singletons in other languages. (Most of those cases have to deal with multi-threading but as JS is single-threaded so I think this would be sufficient way)
Still need opinion on best practices, or any other Dependency Injection methods where we don't even rely on Singleton but create the object once and reuse all over the project with dependency injections.
I would like to know the opinion of sensie in JS.