Open Mtlekvin opened 5 months ago
A newly created object will have Object
as it's prototype, however Object.prototype would always is null
.
Basically the prototype chain has to stop somewhere and it's indicated by null
.
My earlier explanation is incorrect, I could have said this better. To quote from MDN docs
Every object in JavaScript has a built-in property, which is called its prototype. The prototype is itself an object, so the prototype will have its own prototype, making what's called a prototype chain. The chain ends when we reach a prototype that has null for its own prototype.
https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Object_prototypes
Object.prototype will be equal to any primitive value as well, not just null. For example Object.prototype can be equal to 5.
This is false. Maybe you can provide some code example/docs for reference.
The following is what I get in NodeJS repl.
> Object.prototype
[Object: null prototype] {}
how does Object.prototype affect something when its instances do not get a prototype equal to null or any other primitive?
To answer this, I'm again quoting MDN
When you try to access a property of an object: if the property can't be found in the object itself, the prototype is searched for the property. If the property still can't be found, then the prototype's prototype is searched, and so on until either the property is found, or the end of the chain is reached, in which case undefined is returned.
This is false. Maybe you can provide some code example/docs for reference.
Yes, I mistook Object
for Function
.
I understood what you meant to say and corrected the title of the issue to a different one.
But here we have this statement:
So I think it's worth mentioning that
F.prototype
can be equal to null only whenObject.prototype
, but when you set prototype forF.prototype
it's not possible.