HybridPatternExample
function Person(name, age, job) {
this.name = name;
this.age = age;
this.job = job;
this.friends = ['A', 'B'];
}
Person.prototype = {
constructor : Person,
sayName : function () {
console.log(this.name);
}
}
function SuperType(name) {
this.name = name;
this.color = ['red', 'blue'];
}
SuperType.prototype.sayName = function () {
console.log(this.name);
}
function SubType(name, age) {
//继承属性
SuperType.call(this, name);
this.age = age;
}
//继承方法
SubType.prototype = new SuperType();
SubType.prototype.constructor = SubType;
SubType.prototype.sayAge = function () {
console.log(this.age);
}
转载请注明原文地址: https://ju.6miu.com/read-8295.html