Several common inheritance

1, the expansion prototype object inheritance

2, using the apply () and call inheritance

3, a combination of call + prototype inheritance

function person(name){
this.name=name;
}
function.prototype.showName=funciton(){
return this.name;
}
funciton man(name,age){
person.call(this.name);
this.age=age;
}
man.prototype=new person();
man.prototype.showAge=funciton(){
return this.age;
}
var Man=new man ('woshi',12)
man.showName();//woshi
man.showAge();//12

  

Guess you like

Origin www.cnblogs.com/rabbitstudent/p/11882566.html