码迷,mamicode.com
首页 > 其他好文 > 详细

面向对象组合继承

时间:2016-09-24 11:49:26      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

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

面向对象组合继承

标签:

原文地址:http://www.cnblogs.com/ypengbk/p/5902614.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!