what are initcomponent and constructor?
The components provided by ExtJS are quite rich, but sometimes the demand is richer.
When the ExtJS native component fails to fulfill our requirements, it is necessary to extend the ExtJS components to implement the self-made components.
In addition to this use situation, sometimes for some of the same but have a lot of configuration, it may be like to separate it, set as a separate component for everyone to call, save development time and improve code reuse.
InitComponent and constructor are ExtJS provide a way to implement inheritance and extension.
ext.define Implementing Extensions
Using ext.define for extension in ExtJS, InitComponent and constructor are used in a similar way
Ext.define (' Ext.oscar999.button.MyButton ', {extend: ' Ext.button.Button ', initcomponent:function () {//do something}, Constructor:function () {//do Something}});
The general situation, coupled with the definition of xtype, resembles:
(Extended with Ext.extend in the old ExtJS version)
So how do these two usages work? What is the difference between the use of the two?
InitComponent and constructor are different from the contact
1. InitComponent This method is called in the Ext.component Constructor (constructor), and only directly or indirectly inherits from the The Ext.component class will only invoke the InitComponent method in the constructor.
Take a look at the ext.abstractcomponent source file Src/abstractcomponent.js
The initcomponent is called in the constructor method
2.
1) callparent () must be called in the InitComponent function in the custom class, otherwise the caller cannot initialize the object
2) for extension components such as button, the constructor in the custom class needs to call Callparent (arguments), otherwise the caller cannot initialize the object
This.callparent (arguments);
The arguments here is needed.
(In versions prior to ExtJS 4, you might see more XXX.superclass.constructor.call notation)
Sencha's official website has a discussion of these two differences:
Http://www.sencha.com/forum/showthread.php?47210-constructor-Vs-initComponent
However, the grammar is based on ExtJS three discussions, I think the role is not very large.
In the actual development experience of the author, basically using initcomponent can achieve the development requirements.