面向对象组合继承

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);
原文地址:https://www.cnblogs.com/zhangxy1018/p/5920638.html