I'm reading a tutorial about inheritance in JavaScript, and there is the following statement:
For an object of Rabbit class to inherit from Animal class we need:
- Define Animal
- Define Rabbit
Inherit Rabbit from Animal:
Rabbit.prototype = new Animal()
They say that this approach has a disadvantage of a need to create a redundant object. I don't understand why I need to create that redundant object? I've tried the following and it worked without creating redundant objects:
function Animal() {};
function Rabbit() {};
Rabbit.prototype = Animal.prototype
Animal.prototype.go = function() {alert("I'm inherited method"};
var r = new Rabbit();
r.go();
What am I missing here?