ES5继承问题举例实现

//父类:person
function Person(name){
this.name = name;
}
Person.prototype.say = function(){
console.log(this.name);
}
//子类:Doctor
function Doctor(name,major){
Person.call(this,name);
this.major = major;
}

Doctor.prototype = nee Person();
Doctor.prototype.constructor = Doctor;
Doctor.prototype.kanbing = function(){
console.log(`${this.name}正在${this.major}看病`);
}
//产生医生实例,并测试调用方法
var ml = new Doctor('马六',"儿科");
ml.say();
ml.kanbing();

posted @ 2020-10-22 16:17  小布pro  阅读(84)  评论(0)    收藏  举报