admin管理员组

文章数量:1391995

I was trying to understand the prototype chain of the code below

const parentObject = {
    name: "Parent",
    nested: {
        key: "value"
    },
    greet: function () {
        return `Hello from ${this.name}`;
    }
};


const childObject = Object.create(parentObject);
childObject.name = "Child"; 

console.log(childObject); 

from which I get the following in the console:

Nonetheless, expanding constructor's prototype, then __proto__ I get

which points to a different __proto__, null. Isn't the prototype of a constructor supposed to point to the original Object (in this case "parentObject")? If that is so, why they differ their proto? If possible, is there a reliable diagram that well depicts what is going on?

本文标签: javascriptwhy constructor39s proto is pointing to null while its original prototype doesn39tStack Overflow