87,989
社区成员
发帖
与我相关
我的任务
分享
function inheritPrototype(subType, superType) {
function F() {}
F.prototype = superType.prototype;
subType.prototype = new F();
subType.prototype.constructor = subType;
}
function SuperType(name) {
this.name = name;
this.colors = ["red", "blue", "green"];
}
SuperType.prototype.sayName = function () {
return this.name;
};
function SubType(name, age) {
SuperType.call(this, name);
this.age = age;
}
inheritPrototype(SubType, SuperType);
SubType.prototype.sayAge = function () {
return this.age;
};
var sub = new SubType("zk", 25);
console.log(sub);
