首页 > 代码库 > 面向对象组合继承

面向对象组合继承

function Person(name,sex,age){
this.name = name;
this.sex = sex;
this.age = age;
}
Person.prototype.eat = function(){
console.log("每个人都会吃饭");
}
function Programmer(name,sex,age){
this.habby = "看书";
Person.call(this,name,sex,age)
}
Programmer.prototype = Person.prototype;
Programmer.prototype.writeCode = function(){
console.log("写代码");
}

var programmer = new Programmer("张三","男",20);
console.log(programmer);

面向对象组合继承