Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not quite complete statement in summary #3663

Open
Mtlekvin opened this issue Jan 30, 2024 · 3 comments
Open

Not quite complete statement in summary #3663

Mtlekvin opened this issue Jan 30, 2024 · 3 comments

Comments

@Mtlekvin
Copy link

Mtlekvin commented Jan 30, 2024

ffdsfsd
https://javascript.info/function-prototype - on this page in the summary we have this statement:

The value of F.prototype should be either an object or null: other values won’t work.

But here we have this statement:

If the prototype of a function is reassigned with something other than an Object, when the function is called with new, the returned object's prototype would be Object.prototype instead. (In other words, new ignores the prototype property and constructs a plain object.)

So I think it's worth mentioning that F.prototype can be equal to null only when Object.prototype, but when you set prototype for F.prototype it's not possible.

@prakhar-pal
Copy link

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.

@prakhar-pal
Copy link

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.

@Mtlekvin Mtlekvin changed the title Wrong statement in summary Not quite accurate statement in summary Feb 6, 2024
@Mtlekvin Mtlekvin changed the title Not quite accurate statement in summary Not quite complete statement in summary Feb 6, 2024
@Mtlekvin
Copy link
Author

Mtlekvin commented Feb 6, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants