-
Notifications
You must be signed in to change notification settings - Fork 8
Naming bikeshed #3
Comments
I had noted this in a previous version of the proposal, but there also exists Object.entries(object) // "own" enumerable properties
Map.prototype.entries()
Set.prototype.entries()
FormData.prototype.entries()
// etc. If |
It's absolutely different data structures. |
I still think the parallel is stronger between data structures like Object.entries() // array
Map.prototype.entries() // iterator
Object.keys() // array
Map.prototype.keys() // iterator
I think for the use case of "objects-as-dictionaries" people would sooner relate them to other data structures like maps and sets long before they would relate them to |
Ok, |
Maybe someone else can comment on the mental model that should be used for symbols. My understanding of how they get modeled into the language is that they should always be observable when you have access to them already, and (generally) not be observable when you don't have access to them. I thought Using that mental model, it makes sense that enumerating methods like For non-enumerable object properties, I think this is just covering the inherent differences between |
Back on the main point, you're very likely to get criticism in committee that |
The names on Reflect imo already lack consistent consistency: I'm not sure there's a strong naming argument to be made whatsoever based on |
Oh to be clear, I'm just trying to make the point that there is a tradeoff here between mirroring other javascript data structures vs differentiating the method from I think an important difference here is that data structures like Object, Map, Set, etc are a daily part of using modern JavaScript, where using something like Reflect is extremely rare. Searching through publicly available code, it's difficult to find real-world examples of developers using Being so rare, it seems unlikely that any JS engineers would have confusion around |
@ljharb sorry, but it's a strange argumentation and it's not applicable here. We talk only about |
The several intersecting methods of For example, But if the argument is about intersecting methods on different objects, we should be looking at
If you start listing them all out, there is a pretty clear pattern here: Object.keys()
Map.prototype.keys()
Set.prototype.keys()
FormData.prototype.keys()
URLSearchParams.prototype.keys()
Object.values()
Map.prototype.values()
Set.prototype.values()
FormData.prototype.values()
URLSearchParams.prototype.values()
Object.entries()
Map.prototype.entries()
Set.prototype.entries()
FormData.prototype.entries()
URLSearchParams.prototype.entries()
// Object.has() -- missing!
Map.prototype.has()
Set.prototype.has()
FormData.prototype.has()
URLSearchParams.prototype.has() This isn't a coincidence, it's not the result of different features being added at different times. It's the result of intentional design choices. Design choices that are worth preserving between the data structures that JavaScript developers use everyday. |
@jamiebuilds I came into this thinking |
I'd like to propose BTW, I'd say that Edit: |
"own" is a verb and does not imply that to me. |
Using a completely different name implies that its a completely separate type of operation. But in reality they are the same operation, just for different data types. Look at In that sense, "objects-as-dictionaries" is a well established pattern in JavaScript that already has APIs built around it. APIs that are built to mirror |
Completely agree, and that's why I think |
Yeah |
Stage 2 UpdateThis proposal was promoted to Stage 2 on April 20, 2021. The full agenda notes have not been published yet. But the committee agreed to move forward with the name |
These probably were meant to be `Object.hasOwn` per tc39#3 (comment)
These probably were meant to be `Object.hasOwn` per #3 (comment)
If the function would always return |
It wouldn’t; it would check either string or symbol keys, just like hasOwnProperty. |
This proposal has reached Stage 3 so the name |
I don't quite follow. The README links here for "Why Was there reasoning for |
There was a bunch of justification not to use You can read the notes here: https://github.com/tc39/notes/blob/25ea12a2f9c0f41588119e94aa01997299adb7f5/meetings/2021-05/may-25.md#accessible-objectprototypehasownproperty-for-stage-3 |
awesome, thanks for that 😄 |
I perfectly understand that
has
is more frequent name thanhasOwn
for this shortcut, but we haveReflect.has
which works likein
operator. The restReflect
methods work similarly toObject
methods - we should avoid this inconsistency. Also, I think, the method name should point to check own properties.Edit from @jamiebuilds:
This proposal was presented to TC39 on April 20, 2021, where it went forward to Stage 2 but the name was left in question. This issue should be used for discussing the method name further.
The text was updated successfully, but these errors were encountered: