三、 组合继承 (原型链和借用构造函数的技术组合到一起)
```javascript
function SuperType(name){
this.name = name;
this.colors = ['red','yellow'];
}
SuperType.prototype.sayName = function(){
alert(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(){
alert(this.age);
}
var a = new SubType("Alex",18);
var b = new SubType("John",21);
a.colors.push("black");
console.log(a.colors)//['red','yellow','black'];
a.sayName();//Alex
a.sayAge();//18
b.colors;//["red","yellow"];
四、寄生组合式继承(集寄生式继承和组合继承的优点于一身,是实现基于类型继承的最有效方式)
function SuperType(name){
this.name = name;
}
SuperType.prototype.sayName = function(){
alert(this.name);
}
function SubType(name,age){
SuperType.call(this,name);
this.age = age;
}
function object(o){
function F(){};
F.prototype = o;
return new F();
}
function inheritProtyotype(sub,parent){
var prototype = object(parent.prototype);
prototype.constructor = sub;
sun.prototype = prototype;
}