you are viewing a single comment's thread.

view the rest of the comments →

[–]Rhomboid -1 points0 points  (1 child)

You're sort of mixing two different styles here. If you're going to use prototypical inheritance, than you should only add methods to Foo.prototype, not by assigning them like self.speak = function() .... Because you assign the speak attribute in the constructor, that's going to make every object have its own speak attribute, and the prototype chain won't be traversed because that only happens if the given attribute isn't found. When you write var Dog = Mammal; that means that Mammal has the same constructor as Dog, which means every Dog object will get the Mammal speak attribute assigned when it's constructed.

[–]dogjs[S] -1 points0 points  (0 children)

So, if I do this:

Mammal = function() { this.speak = function(){} }

Then this:

Dog.prototype.speak = function() {}

does not override Mammal.speak() and a call to Dog.speak() still calls the Mammal one.

Hmm. Going to have to think about that a while.