Extjs 之 initComponent 和 constructor的区别(转)
(在舊的Extjs 版本中使用 Ext.extend 實(shí)現(xiàn)擴(kuò)展)
Ext.define('Btn',{
extend:'Ext.button.Button',
initComponent:function(){
alert('后初始化部件啟動(dòng)...');
},
constructor:function(){
this.text = new Date();
this.renderTo = Ext.getBody();
this.callParent();
alert('先構(gòu)造函數(shù)啟動(dòng)...');
}
});
Ext.onReady(function(){
Ext.create('Btn');
});
initComponent是在construor里被調(diào)用,constructor是在其他地方調(diào)用;一個(gè)用于具體的創(chuàng)建控件,一個(gè)是用于創(chuàng)建控件對(duì)象
http://blog.csdn.net/oscar999/article/details/33743171
1. initComponent這個(gè)方法是在Ext.Component的構(gòu)造函數(shù)(constructor)中調(diào)用的,只有直接或間接繼承自 Ext.Component的類才會(huì)在constructor里調(diào)用initComponent方法
看一下? Ext.AbstractComponent的源碼文件 src/AbstractComponent.js
在? constructor方法中調(diào)用了initComponent
2.
?? 1)自定義類中的 initComponent 函數(shù)中必須調(diào)用 callParent();否則 調(diào)用者無法初始化這個(gè)對(duì)象
?? 2)針對(duì)button 這樣的擴(kuò)展組件來說,自定義類中的? constructor ,需要調(diào)用callParent( arguments);否則 調(diào)用者無法初始化這個(gè)對(duì)象
[html] view plaincopy?
(在Extjs 4 之前的版本中, 可能會(huì)看到比較多的XXX.superclass.constructor.call 寫法)http://blog.csdn.net/alastormoody/article/details/8251018
Extjs之superclass.constructor.call(this)之理解
Ext.extend()函數(shù)提供了直接訪問父類構(gòu)造函數(shù)的途徑,通過 SubClass.superclass.constructor.call(this);就可以直接調(diào)用父類的構(gòu)造函數(shù),這個(gè)函數(shù)的第一個(gè)參數(shù)總是 this,以確保父類的構(gòu)造函數(shù)在子類的作用域里工作。
轉(zhuǎn)載于:https://www.cnblogs.com/givemeanorange/p/5570214.html
總結(jié)
以上是生活随笔為你收集整理的Extjs 之 initComponent 和 constructor的区别(转)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python 学习(1)
- 下一篇: Mysql 学习笔记2