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();

浙公网安备 33010602011771号