【发布时间】:2011-10-05 03:33:05
【问题描述】:
与constructor 相比,我应该什么时候使用initComponent?
我一直在使用 initComponent 来扩展我的对象,但是查看 Ext.define 的文档会看到它们到处都使用构造函数。有什么区别?
比较:
Ext.define('My.app.PanelPart2', {
extend: 'My.app.Panel',
constructor: function (config) {
this.callSuper(arguments); // calls My.app.Panel's constructor
//...
}
});
到
Ext.define('My.app.PanelPart2', {
extend: 'My.app.Panel',
initComponent: function (config) {
Ext.apply(this, config);
this.callParent(arguments);
}
});
我知道有些组件没有初始化(我在看着你Ext.data.Store),这导致我倾向于只编写构造函数,因为这应该是通用的。
【问题讨论】: