MyApp=function(){vardata;//data is private and can't be accessed from outside.return{init:function(){console.log('init');//Initialize application here},getData:function(){returndata;}};}();Ext.onReady(MyApp.init,MyApp);
Observable观察者模式
Ext.util.Observable使用events实现在多个objects之间解耦
事件触发流程:state changes -> fire event -> notified
12345678910111213141516
varMyClass=Ext.extend(Ext.util.Observable,{constructor:function(config){this.addEvents('datachanged');//specify the events we're going to fire},update:function(){this.fireEvent('datachanged',this,arguments.length);}});// To subscribe to an eventvarc=newMyClass();c.on('datachanged',function(obj,num){console.log(num);});c.update(2,8,'some');//3