私はいくつかのjavascript継承の例を試していますが、これで壁にぶつかりました:
function Animal(){}
Animal.prototype.type = "animal";
Animal.prototype.speak = function(){ console.log( "I'm a " + this.type +
". I can't really talk ;)" ); }
function Dog(){}
function F(){}
F.prototype = Animal.prototype;
Dog.prototype = new F();
Dog.prototype.constructor = Dog;
Dog.prototype.type = "Dog";
Dog._super = Animal.prototype;
Dog.woof = function(){ console.log( "Woof!" ); _super.speak(); }
var rover = new Dog();
rover.woof();
私はこれを取得していますが、理由がわかりません:
TypeError: Object #<Dog> has no method 'woof'
見つからないメソッドをコンストラクター関数に入れることができることは知っていますが、プロトタイプを変更してこれを実行しようとしています。私はここで何が間違っているのですか?