JavaScriptã§ã·ã³ã°ã«ãã³
JavaScriptã§ã®ã·ã³ã°ã«ãã³ã®æ¸ãæ¹ãããã¤ããæãã¤ããç¯å²ã§ã
1.ã¯ã©ã¹å¤æ°çãªæãã§ã¤ã³ã¹ã¿ã³ã¹ãä¿æã
example.ClassX.instance = new example.ClassX();
example.ClassX.instance.call();
2.é¢æ°ã®ã¤ã³ã¹ã¿ã³ã¹å¤æ°ã«ä»è¾¼ãã
example.ClassX.getInstance = function() { var self = arguments.callee; return self.instance || ( self.instance = new example.ClassX() ); }; example.ClassX.getInstance().call();
3.ãã¼ã«ã«å¤æ°ã§privateã«ãã¨ããããã¯ããã¯ããã£ããããªã
example.ClassX.getInstance = function() { var instance = new example.ClassX(); return function() { return instance;}; }(); example.ClassX.getInstance().call();
4.ã¯ã©ã¹èªä½ãå·®ãæ¿ãã¦ãã¾ã!
example.ClassX = new example.ClassX();
example.ClassX.call();
5.ãã£ãã®ãã¨ããã§ããã?
example.ClassX.instance = { call: function(){ ... } } example.ClassX.instance.call();
å人çã«ã¯ããDIã³ã³ããã«ç®¡çãããæ´¾ãã ã£ããããã®ã§ã©ãã使ãã¾ãããã