First of all, JavaScript is not a class based language. It doesn't know about the concept of classes, but it knows about objects and the prototype chain and with those two components, we can simulate class-like behavior and implement inheritance.
But since this all is kind of a workaround, we sometimes have to put extra effort in it, in order to make it work. And this is where your last line Cat.prototype.constructor = Cat comes in.
The prototype property of every function has a property called constructor which points to the function itself. So when you use the function as a constructor, the internal [[prototype]] object has the constructor property as well.
function Cat() {
}
var cat = new Cat();
console.log(Cat.prototype.constructor); //Cat
console.log(cat.constructor); //Cat
But, if you apply your inheritance pattern, you override the complete prototype property of Cat with all its properties, including the constructor property.
function Cat() {
}
Cat.prototype = new Animal();
var cat = new Cat();
console.log(Cat.prototype.constructor); //Animal
console.log(cat.constructor); //Animal
To fix this, we have to set the constructor property manually:
function Cat() {
}
Cat.prototype = new Animal();
Cat.prototype.constructor = Cat;
var cat = new Cat();
console.log(Cat.prototype.constructor); //Cat
console.log(cat.constructor); //Cat