Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SingletonC =T
- LTI OIK
- if (SingletonCounter.singletonInstance) {
- return SingletonCounter.singletonInstance;
- b
- SingletonCounter.singletonInstance = this;
- is.count = 0;
- }
- increment () {
- G
- b
- I
- // Static property to track if an instance exists yet
- SingletonCounter.singletonInstance = n 7
- onst counterl = new SingletonCounter();
- counteril.increment();
- const counter2 = new SingletonCounter();
- counter2.increment();
- // Both counterl and counter2 point to same instance
- console.log(counteri.count); // 2
- console.log(counter2.count); // 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement