Hello Everyone,
I'm reading this article about prototypal inharitance in javascript, which includes the following example:

// class Dog : Pet 
// public Dog(string name, string breed)
function Dog(name, breed) {
    // think Dog : base(name) 
    Pet.call(this, name);
    this.getBreed = function() { return breed; };
    // Breed doesn’t change, obviously! It’s read only.
    // this.setBreed = function(newBreed) { name = newName; };
}

// this makes Dog.prototype inherits
// from Pet.prototype
Dog.prototype = new Pet();

// remember that Pet.prototype.constructor
// points to Pet. We want our Dog instances�/span>
// constructor to point to Dog.
Dog.prototype.constructor = Dog;

// Now we override Pet.prototype.toString
Dog.prototype.toString = function() {
    return “This dog’s name is: �+ this.getName() + 
        � and its breed is: �+ this.getBreed();
};
// end of class Dog

var dog = new Dog(“Buddy� “Great Dane�;


When I follow the code above, this is what I understand:
when "new Dog()" is called (last line), a new object is created, and the function Dog is called upon it.
Inside the Dog() function, there is a call to the constructor Pet() for the newly created object, which in turn adds the Pet properties to the new class, thus practically turning it into a Pet type.
This is how inharitance is implemented here.

My Question is:
Why do we need to assign the prototype for the Dog object? isn't its done when we called the Pet constructor, which turned our object into a pet?

Thanks,
Itay

Check out my blog at http://blogs.microsoft.co.il/blogs/itaysk | Mark my post as helpful if I helped