题解 | #寄生组合式继承#

寄生组合式继承

http://www.nowcoder.com/practice/dd8eb918b5d343cc8be77a69630f59bf

function inhert(subType, superType) {
  subType.prototype = Object.create(superType.prototype);
  Object.defineProperty(subType.prototype, "constructor", {
    enumerable: false,
    writable: true,
    configurable: true,
    value: subType,
  });
}
function Human(name) {
  this.name = name;
  this.kingdom = "animal";
  this.color = ["yellow", "white", "brown", "black"];
}
Human.prototype.getName = function () {
  return this.name;
};
function Chinese(name, age) {
  Human.call(this,name)
  this.color = "yellow";
  this.age = age;
}

inhert(Chinese, Human);

Chinese.prototype.getAge = function () {
  return this.age;
};
全部评论

相关推荐

勤劳的鲸鱼在okr拆解:没有别的选择就去吧,有实习和没实习找工作是天上地下
点赞 评论 收藏
分享
千疮百孔的象牙塔:我也在捣鼓im,你这个im好奇怪的样子,单看简历get不到点,im的消息及时性,消息可靠性,然后系统的可扩展性这几个关键问题都是怎么解决的从简历描述get不到,具体说消息怎么传,消息怎么推送,消息怎么存,消息安全怎么做的这些点感觉对应不起来
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务