//装饰器模式function a(){ console.log('a');}function b(){ console.log('b');}function log(fun){ console.log(new Date()); fun.call(null); console.log(new Date());}// a();//=> new date(),a,new date();// b();log(a);
//单列模式var Singleton = (function(){ var singleton = null; function init(){ return new Object(); } return { getInstance:function(){ if(!singleton){ singleton = init(); } return singleton; } }})();Singleton.getInstance();Singleton.getInstance();Singleton.getInstance();
//备忘录模式,如缓存机制