# {Map, WeakMap, etc}.prototype.getRef(key)

**URL:** <https://es.discourse.group/t/map-weakmap-etc-prototype-getref-key/884>\
**Category:** 💡 Ideas\
**Created:** [July 21, 2021, 4:13pm UTC](https://es.discourse.group/t/map-weakmap-etc-prototype-getref-key/884 "2021-07-21T16:13:09Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![conartist6](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/conartist6/32/515_2.png) [@conartist6](https://es.discourse.group/u/conartist6)\
**Post date:** [November 24, 2022, 3:15am UTC](https://es.discourse.group/t/map-weakmap-etc-prototype-getref-key/884/21 "2022-11-24T03:15:33Z")

</div>

Yes!! That class should be called `List`, and it should exist right alongside `Map` and `Set`.

---

<div class="post-metadata">

**Author:** ![conartist6](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/conartist6/32/515_2.png) [@conartist6](https://es.discourse.group/u/conartist6)\
**Post date:** [November 24, 2022, 3:52am UTC](https://es.discourse.group/t/map-weakmap-etc-prototype-getref-key/884/22 "2022-11-24T03:52:32Z")

</div>

~~What if the syntax was `Map.getRef(myMap, key)`?~~

---

<div class="post-metadata">

**Author:** ![theScottyJam](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/thescottyjam/32/616_2.png) [@theScottyJam](https://es.discourse.group/u/theScottyJam)\
**Post date:** [November 24, 2022, 5:55am UTC](https://es.discourse.group/t/map-weakmap-etc-prototype-getref-key/884/23 "2022-11-24T05:55:29Z")

</div>

What would be the difference between this `List` class and a normal array? Presumably, you'd be required to use `.at()` to index into it, and some other new method to assign items at a particular index (as I'm assuming this won't be an exotic object the same way arrays are). But, would you drop any methods that are currently found on arrays? If so, which?

And, why would anyone choose to create an instance of `List` over just using a normal array?

---

<div class="post-metadata">

**Author:** ![conartist6](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/conartist6/32/515_2.png) [@conartist6](https://es.discourse.group/u/conartist6)\
**Post date:** [November 24, 2022, 9:48pm UTC](https://es.discourse.group/t/map-weakmap-etc-prototype-getref-key/884/24 "2022-11-24T21:48:24Z")

</div>

I see ideal encapsulation as designing the smallest API that creates the possibility of doing any kind of work.

I think the pattern of a rich, featureful array makes a lot of sense in a language where the programmer knows what environment the code will run in, but javascript library authors don't (which causes problems).

---

<div class="post-metadata">

**Author:** ![conartist6](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/conartist6/32/515_2.png) [@conartist6](https://es.discourse.group/u/conartist6)\
**Post date:** [November 24, 2022, 9:58pm UTC](https://es.discourse.group/t/map-weakmap-etc-prototype-getref-key/884/25 "2022-11-24T21:58:24Z")

</div>

And to be clear I don't think either `getRef` or `emplace` is beyond the boundaries of what good encapsulation dictates should belong in `Map` or a potential `List`. I took a closer look at the `emplace` proposal, and while the syntax of it still feels a bit unquantifiably icky to me, I guess I'm OK with it.

---

<div class="post-metadata">

**Author:** ![theScottyJam](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/thescottyjam/32/616_2.png) [@theScottyJam](https://es.discourse.group/u/theScottyJam)\
**Post date:** [November 26, 2022, 3:07pm UTC](https://es.discourse.group/t/map-weakmap-etc-prototype-getref-key/884/26 "2022-11-26T15:07:52Z")

</div>

Ok, thanks for the input - I was mostly curious about your point-of-view, as I hadn't heard of this kind of thing before 👍

[Previous page](https://es.discourse.group/t/map-weakmap-etc-prototype-getref-key/884.md?page=1)
