Advertisement
image2text

Untitled

Sep 22nd, 2019
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. class SingletonC =T
  2. LTI OIK
  3. if (SingletonCounter.singletonInstance) {
  4. return SingletonCounter.singletonInstance;
  5. b
  6. SingletonCounter.singletonInstance = this;
  7. is.count = 0;
  8. }
  9. increment () {
  10. G
  11. b
  12. I
  13. // Static property to track if an instance exists yet
  14. SingletonCounter.singletonInstance = n 7
  15. onst counterl = new SingletonCounter();
  16. counteril.increment();
  17. const counter2 = new SingletonCounter();
  18. counter2.increment();
  19. // Both counterl and counter2 point to same instance
  20. console.log(counteri.count); // 2
  21. console.log(counter2.count); // 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement