题解 | #寄生组合式继承#
寄生组合式继承
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;
};