Advertisement
Guest User

Untitled

a guest
May 25th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. class Singleton {
  2. private static _instance : Singleton;
  3. /**
  4. * TimeUtils
  5. */
  6. public static get instance():Singleton {
  7. if(!this._instance)
  8. this._instance = new Singleton();
  9. return this._instance;
  10. }
  11. private constructor(){}
  12.  
  13. }
  14.  
  15. 目前用過最簡易的 Singleton , 可以在編寫時使用 Singleton.instance 進行調用。 既有 static class 的優點,並且也屬於 instance。
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement