Posted By

shalomfriss on 01/16/15


Tagged

javascript Singleton


Versions (?)

Singletonize


 / Published in: JavaScript
 

A function to turn any class into a singleton

  1. function singletonize(AClass)
  2. {
  3. AClass.getInstance = function()
  4. {
  5. if (!AClass._instance)
  6. {
  7. AClass._instance = new AClass();
  8. }
  9.  
  10. return AClass._instance;
  11. }
  12. }

Report this snippet  

You need to login to post a comment.