-
Notifications
You must be signed in to change notification settings - Fork 19
Naming proposal Array.prototype.itemAt() #33
Comments
|
Yeah, based on informal IRC discussion, it seems like a good number of people might support |
Is there a reason
|
Yeah, as long as there's no compat issues to fear, I support aligning with Maps and using |
I know that EmberJS extends the Array prototype with https://api.emberjs.com/ember/3.8/classes/Ember.NativeArray/methods/get?anchor=get |
|
For lists, that's not my personal intuition, fwiw. |
Noted - also worth pointing out that Set is the analogous List to Array, and Set doesn't have a |
@ljharb That's because Sets are key-without-value: the only thing I do share your concern about |
Conversely, since Sets and Maps are ordered we could reasonably add an |
If we align with Map and Set ("get","set") it might break if someone use "set" in object to determinate if it is a map or set. |
I can't tell what you mean by this. |
I feel like adding an analogous Either way, I'm strongly in favor of aligning with Map's method naming to avoid repeating the mistake of the completely unnecessary confusion of length/size, has/includes, etc. for similar methods and properties. Furthermore, something like |
@tabatkins i mean, in my mental model, Set and Array are “lists” and Map and Object are “structs” (insert any conceptual term you feel better fits). |
@0kku “length” on Map/Set would have made them be considered “arraylikes”, and since they’re not accessible by index, that would have caused much more confusion and bugs. Similarly, arrays are fundamentally different in some ways from Maps and Sets, and consistency in method names isn’t inherently a good thing (nor inherently a bad thing, of course). |
I don't know was it already discussed at the current TC39 meeting or not, but my 2 cents:
I think that makes sense to try to use this name and to absorb this proposal - with proposed semantic, but with negative indexes. I hope that no one tried to use negative indexes with |
@zloirock that core-js has a code point-returning polyfill might actually make that name web incompatible :-/ was it enabled by default in any core-js versions? |
@ljharb yes, I perfectly understand it. It's in the full (with all proposals) set of polyfills from the first |
Because with nonnegative indexes, it returns a code unit, not a code point. |
But why not to make this proposal work like this: 'a𠮷b'.at(1); // => '𠮷'
'a𠮷b'.at(-3); // => '𠮷' ? If I understood correctly, it's still a controversial issue. |
Consensus was reaffirmed today for the current code point semantics; |
Ok, in the case of code units semantic, it's really could be a problem. |
This comment has been minimized.
This comment has been minimized.
@Zarel yes, i made a typo, thanks for correcting me. Fixed. |
I'm seeing that
.item()
is running into compatibility problems. I haven't seen.itemAt()
proposed anywhere and it seems to be the most succinct alternative.The text was updated successfully, but these errors were encountered: