function inheritPrototype(childObject, parentObject) { var copyOfParent = Object.create(parentObject.prototype); copyOfParent.constructor = childObject; childObject.prototype = copyOfParent; }
Why is
copyOfParent.constructor = childObject;
needed?
A source on the internet explained:
Then we set the constructor of this new object to point to the childObject. This step is necessary because the preceding step overwrote the childObject constructor when it overwrote the childObject prototype (during the Object.create() process)
How can it have overwritten the childObject constructor when this is the first time the childObject parameter is being used?