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

寄生组合式继承

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

相关推荐

11-14 16:13
已编辑
重庆科技大学 测试工程师
Amazarashi66:不进帖子我都知道🐮❤️网什么含金量
点赞 评论 收藏
分享
SinyWu:七院电话面的时候问我有没有女朋友,一听异地说你赶紧分。我:???
点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务