-
Notifications
You must be signed in to change notification settings - Fork 62
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
Will __proto__ be treated as prototype for records? #46
Comments
I don't think Records have a proto. They don't participate in prototype chains. |
Typically every primitive that's dotted or bracketed into creates a boxed object, on which |
@ljharb do you think there is a way to achieve all three of the following?
(similar questions apply for |
@mheiber number 1 in that list would mean that these new types must be objects, not primitives, since dot/bracket access always either throws (nullish), or boxes into an object and returns the resulting property (primitive), or returns the resulting property (object). |
Sounds like there's no way, then. Anything with Object in its prototype chain is mutable, as far as I know. |
It’s not about mutability; it could have a [[Prototype]] of null like |
iow i think the “bare member access” feature requires it be a proxy, a normal object, or a brand new kind of thing. |
I think we have two alternatives here:
I can't make of my mind which one of these I like better. |
Does anyone have any thoughts on 1 vs 2 of #46 (comment) ? I guess I'm leaning towards 2. (I hope this is relatively easy thing to nail down; it's a bit of an edge case.) |
I personally think it should be consistent, so 1 would be appropriate. Forcing it to set it as a computed property could confuse more than the alternative I consider Anyway, this use case never comes up, so I don't consider this a huge deal. |
@andre-matulionis-ifood I agree that consistency should be the main goal here. But I'm confused; isn't |
I meant to focus on the "property" aspect. @ljharb put it best:
AFAIK, no property has different behavior whether it is set as Another alternative is that it would throw a error independently of setting through |
@andre-matulionis-ifood
https://tc39.es/ecma262/#sec-__proto__-property-names-in-object-initializers So a = { __proto__: { x: 1 } }
Object.getPrototypeOf(a) === a.__proto__ // true
a.x // 1
b = { ["__proto__"]: { x: 1 } }
Object.getPrototypeOf(b) === b.__proto__ // false
b.x; // undefined Neither 1 or 2 are necessarily consistent. 1 changes the behavior so this special case is ignored for records while 2 effectively keeps the special case but throws because its not allowed, yet still preserves the ability to set that key using a computed property name. |
That was the thrust of my comment; since |
Thanks for the correction. I forgot to put So my opinion is not valid. I don't have any comments about these alternatives. |
OK, I think this conversation was still good to have on the record in case others are coming from a similar place as @andre-matulionis-ifood . Can we conclude option 2 of #46 (comment) then, of banning |
I’m not sure those are the only two options; we could also make it set the [[Prototype]] just like normal objects do, since that’s not what makes it a Record. |
Does anyone want to advocate for that option? I'd prefer if we omitted that feature. |
I can see value in creating a record with a null proto, just like when i create objects with one. Forcing a separate Object.setPrototypeOf would be unfortunate (and would records then have |
One possibility is that Records would always have a null prototype. Personally, I'm leaning towards that, even while Tuples have a non-null prototype for Array-like methods.
I don't think Object.setPrototypeOf would work on Records; it'd throw a TypeError unless you gave null.
It seems like we all agree that Records should be able to have a data property named |
I personally lean towards option 2 ( You could, in theory, allow Given that, |
I'd like to treat |
@Jack-Works Can you say more about where you disagree with the reasoning described above? |
proto is a old special case on the object literal. (Same argument for throwing on eval?.()) |
How should we establish whether this assertion about developer intuition is true? Earlier in this thread, people were wondering whether I see the |
I'm not guessing that what I want to tell them this doesn't work. When a developer wants to do this, they will try it Using
|
In normal object literal, both So the current solution ( I think there are three ways:
|
In the following:
Is the expectation that x.y === 10?
The text was updated successfully, but these errors were encountered: