SHARE
TWEET

Untitled

image2text Sep 22nd, 2019 141 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top