原型链继承的问题
看书的时候,有这么一句话,还有一个例子
这句话着这样的:通过原型链实现继承时,不能使用对象对面量创建原型的方法。因为这样做就会重写原型链。
这句话我实在不明白,然后再看例子:
function ChaoLei(){ this.ageone = 1; } ChaoLei.prototype.getChaoleiValue = function(){ return this.ageone; }; function ZiLei(){ this.agetwo = 2; } //继承了超类 ZiLei.prototype = new ChaoLei(); //添加新方法 ZiLei.prototype={ getZileiValue:function(){ return this.agetwo; }, //重写超类中的方法 [color=#FF0000]someOtherMether[/color]:function(){ return 3; } } var instance =new ZiLei(); alert (instance.getChaoleiValue());