dvas0004 / NerdNotes

A collection of notes: things I'd like to remember while reading technical articles, technical questions I couldn't answer, and so on.
12 stars 0 forks source link

WeakMap #37

Open dvas0004 opened 5 years ago

dvas0004 commented 5 years ago

WeakMap is a javascript map where keys can be anything, including JS objects. Contrast this to other maps where keys must be primitives. In addition, since the map is "weak", keys are only weakly referenced. In other words, once there are no more references to a key, that key is garbage collected and removed from the WeakMap.

Note that WeakMaps do not allow for iteration, and only have a basic "get" method to retrieve info on keys

Sometimes used to help with encapsulation

dvas0004 commented 5 years ago

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap