In second code "Bird.prototype and Dog.prototype is not instance of Animal"
Why is so? No such problem in first code.
//First
function Animal() { }
function Bird() { }
function Dog() { }
Bird.prototype = Object.create(Animal.prototype);
Dog.prototype = Object.create(Animal.prototype);
// Only changes in code below this line
Bird.prototype.constructor=Bird;
Dog.prototype.constructor=Dog;
let duck = new Bird();
let beagle = new Dog();
//Second
function Animal() { }
function Bird() { }
function Dog() { }
Bird.prototype = Object.create(Animal.prototype);
Dog.prototype = Object.create(Animal.prototype);
// Only change code below this line
Bird.prototype={constructor:Bird};
Dog.prototype={constructor:Dog};
let duck = new Bird();
let beagle = new Dog();
instanceofdoes not depend onconstructor, but rather "prototype chain", which is apparently broken by the second approach. See this post for more details