Today, looking at someone else's code, you find that the function you called is not what you think it is. So take a serious look at the code, and then combine the previous JS about call notes. Know the reason for this
The code is as follows |
Copy Code |
Son.superclass.initComponent.call (this);
|
Call here is to invoke the InitComponent function of the "Son" parent class and pass this in, this is the Son instance object.
Here is a JS code to explain what this call is
The code is as follows |
Copy Code |
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 (), so test () inside of this is dog, that is, THIS.name is dog.name, that is, pop-up ' Lil ' |
As shown in the above code, Test.call (dog) is equivalent to Dog.test ();
Here's an example of ExtJS code
The code is as follows |
Copy Code |
Son = Ext.extend (father,{ Initcomponent:function () { Son.superclass.initComponent.call (this);//This invokes the InitComponent method of the parent class, that is, the Father InitComponent method, and put this, The son instance object is passed as a parameter }, Test:function () { Alert (' Test in Son '); } } Father = ext.extend (ext.panel,{ initcomponent:function () { & nbsp; Father.superclass.initComponent.call (this); this.test (); This is the instance object of son, equivalent to son son = new son (); Son.test (); //So the test method of the subclass is invoked instead of the test method of the parent class, which I thought was the test method for invoking the parent class }, test:function () { alert (' Test in Father '); } } |