When should I be using initComponent compared to constructor ?
I have been using initComponent to extend my objects, but looking at the docs for Ext.define is see them using constructor all over then place. what is the difference?
compare:
Ext.define('My.app.PanelPart2', {
extend: 'My.app.Panel',
constructor: function (config) {
this.callSuper(arguments); // calls My.app.Panel's constructor
//...
}
});
to
Ext.define('My.app.PanelPart2', {
extend: 'My.app.Panel',
initComponent: function (config) {
Ext.apply(this, config);
this.callParent(arguments);
}
});
I am aware of the fact that some components don’t init ( Im looking at you Ext.data.Store ), which leads me towards leaning towards only over writing the constructor, as that should be universal.
constructoris OOP standard for initializing objects instances and is available in every ExtJS class (everything created byExt.define).initComponentis ExtJS extension for initializing components – classes that extendsExt.Component. It uses templated method pattern and enables some standard initialization steps before and after your custom component init. Something like this:My best pratices are to use
initComponentwhenever I’m creating custom component andconstructoronly for generic classes.