목적
객체 생성에 관련된 패턴입니다.
단일 인스턴스만 존재하는 클래스 패턴입니다
구조
코드 샘플
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
   | var Singleton = (function () {     var instance;       function createInstance() {         var object = new Object("I am the instance");         return object;     }       return {         getInstance: function () {             if (!instance) {                 instance = createInstance();             }             return instance;         }     }; })();   function run() {       var instance1 = Singleton.getInstance();     var instance2 = Singleton.getInstance();       alert("Same instance? " + (instance1 === instance2));   }
  | 
 
참조사이트