I have read javascript call in the tutorial video. This method is very common in ExtJs.
In the past, when ExtJs was involved, the initComponent code was always ignored, as shown below. Today, when reading other people's code, I found that the called function is different from what I imagined. So I carefully read the code and then combined the previous js call notes. I understand the cause.
Son. superclass. initComponent. call (this );
Here the call is to call the initComponent function of the parent class "Son" and pass this in. this is the Son instance object.
The following uses a js Code to explain how this call works.
Function Dog (name ){
This. name = name;
}
Function test (){
Alert (this. name );
}
Var dog = new Dog ('lil ');
Test. call (dog); // This sentence is equivalent to dog. test (); therefore, this in test () is dog, that is, this. name is dog. name: 'lil' is displayed'
As shown in the code above, test. call (dog) is equivalent to dog. test ();
The following is an example of ExtJs code.
Son = Ext. extend (Father ,{
InitComponent: function () {Son. superclass. initComponent. call (this); // call the initComponent method of the parent class, that is, the Father initComponent method, and pass this and Son instance objects as parameters },
Test: function (){
Alert ('test in son ');
}
}
Father = Ext. extend (Ext. Panel ,{
InitComponent: function () {Father. superclass. initComponent. call (this );
This. test (); // here this is the Son instance object, equivalent to Son son = new Son (); son. test ();
// Therefore, the test method of the subclass is called instead of the test method of the parent class. I thought it was to call the test method of the parent class.
},
Test: function (){
Alert ('test in Father ');
}
}