面向对象组合继承

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);
posted @ 2016-09-24 10:22  莫尘y  阅读(105)  评论(0编辑  收藏  举报