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

寄生组合式继承

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;
};
全部评论

相关推荐

无情咸鱼王的秋招日记之薛定谔的Offer:好拒信,偷了,希望有机会用到
点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务