When not using the 'new' keyword, the constructor logged in the console shows what the constructor of the object is and it also changes when I change the __proto__
of the object it the console also displays what the current constructor of the object is. But when using the 'new' keyword even I change the __proto__
the console still shows the constructor of the original constructor that made the object.
With 'new' keyword photo
The console displays what is the current constructor of the object is, and it changes when I change its __proto__
function Human(){}
function Animal(){}
const obj = Object.create(Human.prototype)
console.log(obj)
Object.setPrototypeOf(obj, Animal.prototype)
console.log(obj)
But when using the new keyword even if change the __proto__
of the object it still displays the original constructor it was created from.
function Human(){}
function Animal(){}
const obj = new Human()
console.log(obj)
Object.setPrototypeOf(obj, Animal.prototype)
console.log(obj)