Call method of ExtJs and JavaScript

Source: Internet
Author: User

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 ');
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.