There was too much nonsense written in the previous article and it was poorly written. Let’s talk about inheritance this time. We knew the prototype in the previous section. Now I start from the prototype to implement the method
function occupation(){
var Notes="Go to work every day";
}
occupation.prototype.work=function(name){
return name "Go to 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.On TV=function(person){
return person "On TV";
}
function clown(){
}
Clown. prototype.line=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(Xiao Zhuo. Work("Xiao Zhuo"));
alert(Xiao Zhuo. Outfit());
alert(Xiao Zhuo. Go to TV("Xiao Zhuo. Zhuo's show"));
//-->
Just wrote a small example of inheritance.
In this way, it is a bit absurd to do this without considering the parent class method and the subclass method. Let me write this
first, and then write later.