在建立自定義類時,先構造(constructor)後初始化(initComponent)。如:
(在舊的Extjs 版本中使用 Ext.extend 實現擴展)
Ext.define('Btn',{
extend:'Ext.button.Button',
initComponent:function(){
alert('後初始化部件啓動...');
},
constructor:function(){
this.text = new Date();
this.renderTo = Ext.getBody();
this.callParent();
alert('先構造函數啓動...');
}
});
Ext.onReady(function(){
Ext.create('Btn');
});
initComponent是在construor裏被調用,constructor是在其餘地方調用;一個用於具體的建立控件,一個是用於建立控件對象
http://blog.csdn.net/oscar999/article/details/33743171
1. initComponent這個方法是在Ext.Component的構造函數(constructor)中調用的,只有直接或間接繼承自 Ext.Component的類纔會在constructor裏調用initComponent方法html
看一下 Ext.AbstractComponent的源碼文件 src/AbstractComponent.js函數
在 constructor方法中調用了initComponentthis
2.spa
1)自定義類中的 initComponent 函數中必須調用 callParent();不然 調用者沒法初始化這個對象.net
2)針對button 這樣的擴展組件來講,自定義類中的 constructor ,須要調用callParent( arguments);不然 調用者沒法初始化這個對象orm
這裏的arguments 是須要的。
(在Extjs 4 以前的版本中, 可能會看到比較多的XXX.superclass.constructor.call 寫法)
http://blog.csdn.net/alastormoody/article/details/8251018
Ext.extend()函數提供了直接訪問父類構造函數的途徑,經過 SubClass.superclass.constructor.call(this);就能夠直接調用父類的構造函數,這個函數的第一個參數老是 this,以確保父類的構造函數在子類的做用域裏工做。xml