var instance1 = new SubType("Nicholas", 29);
instance1.colors.push("black");
alert(instance1.colors); //"red,blue,green,black"
instance1.sayName(); //"Nicholas";
instance1.sayAge(); //29
var instance2 = new SubType("Greg", 27);
alert(instance2.colors); //"red,blue,green"
instance2.sayName(); //"Greg";
instance2.sayAge(); //27
原型式继承(Prototypal Inheritance):
复制代码 代码如下:
function object(o){
function F(){}
F.prototype = o;
return new F();
}
--------------------------------------------------------------------------------
寄生式继承(Parasitic Inheritance):
缺点同构造函数
您可能感兴趣的文章: