Would it be fair to say this is similar to the singleton pattern?
-
-
-
I think it's fair to say that you could implement the singleton pattern using this approach!
Kraj razgovora
Novi razgovor -
-
-
Returning a value from a constructor is not an ES6 thing. Furthermore, this could be achieved more simply as shown. I personally wouldn't do this though as `new` communicates a *new* instance. Why not use a curried function that returns a singleton if you want a singleton?pic.twitter.com/INPQUQbZvC
-
I know it's not an ES6 thing, I'm saying that you can do it with ES6 classes. Your solution is not the same, as the returned instance will not have the methods of ImmutableClass.
- Još 2 druga odgovora
Novi razgovor -
-
-
I would expect a new instance when I use a constructor. for singleton pattern, using a method like ‘getInstance’ is more intuitive than a constructor IMHO.
Hvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi
-
-
-
Along that line I sometimes want to do this:pic.twitter.com/W1ww4qsJMX
Hvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi
-
-
-
What app is that?

Hvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi
-
-
-
But Why do you want it?
-
e.g for classes handling hardware resources (where you want to make sure there is only ever 1 handler)
- Još 1 odgovor
Novi razgovor -
Čini se da učitavanje traje već neko vrijeme.
Twitter je možda preopterećen ili ima kratkotrajnih poteškoća u radu. Pokušajte ponovno ili potražite dodatne informacije u odjeljku Status Twittera.
core contributor
generative art and plotters
new dad
he/him