2015-01-11 14:40
提问者采纳
在创建自定义类时,先构造(constructor)后初始化(initComponent)。如:
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');
});
本文详细解析了ExtJS4框架中initComponent与constructor的区别与使用场景。通过一个具体的自定义类实例,展示了构造函数(constructor)与初始化方法(initComponent)的调用顺序,帮助开发者更好地理解二者的作用及如何正确应用。
1万+

被折叠的 条评论
为什么被折叠?



