Object.create() method creates a new object, using an existing object
Object.create(Shape.prototype) is used in the following example for inheritance.
Rectangle.prototype = Object.create(Shape.prototype); line of code overwrite
Rectangle.prototype field. So, there were
Rectangle constructor in
Rectangle.prototype but after overwritten, constructor field will be removed.
So let's see in debug time.
Rectangle.prototype has a
constructor field which is equal to
function Rectangle() as shown in the following screenshot.
I step over the debugger next line and check the value of
Rectangle.prototype doesn't have a
constructor field this time.
Let me show you
Rectangle.prototype.__proto__. As shown in the screenshot, there is a
function Shape() constructor under
If you don't set
Rectangle.prototype.constructorto Rectangle, it will take the prototype.constructor of Shape (parent). To avoid that, we set the prototype.constructor to Rectangle (child).
Rectangle.prototype has a constructor named
Find the code below