I wrote too much nonsense in the previous article and it was very bad to write. Let's talk about inheritance this time. We learned prototype in the previous section. Now I am going to start with prototype to implement it.
<Scr limit pt LANGUAGE = "Limit Cr limit pt">
<! --
Function occupation (){
Var notice = "work well every day ";
}
Occupation. prototype. Work = function (name ){
Return name + "work ";
}
Occupation. prototype. Off duty = function (){
Return "off duty ";
}
Function. prototype. extend = function (superClass ){
For (var $ p in superClass. prototype ){
This. prototype [$ p] = superClass. prototype [$ p];
}
Delete $ p;
}
Function actor (){
}
Actor. prototype. Television = function (person ){
Return person + "TV ";
}
Function clown (){
}
Clown. prototype. Line header = function (){
Return "exaggerated smile ";
}
Actor. extend (occupation );
Var Zhang San = new actor ();
Alert (Zhang San. Go to work ("Zhang San "));
Clown. extend (actor );
Var xiaozhuo = new clown ();
Alert (xiaozhuo. Go to work ("xiaozhuo "));
Alert (xiaozhuo. Line header ());
Alert (xiaozhuo. TV ("xiaozhuo's show "));
// -->
</Scr platinum pt>
Only a small example of inheritance is written.
In this way, it is a bit difficult to do this without considering the parent class method and subclass method. Write to this
Later.