How to Use WeakMap for Private Data

WeakMap keys are objects. Garbage collected. No leaks.

#javascript #weakmap #private #howto

https://www.youtube.com/watch?v=Ks7v9Twn9vU

How to Use WeakMap for Private Data #javascript

YouTube

WeakMap REJECTS Primitive Keys?!

WeakMap has a SECRET rule! It ONLY accepts objects as keys. Try to use a string and it FAILS silently. This hidden restriction will cause bugs you'll never find!

#javascript #javascripttricks #weakmap #objectkeys #javascriptweird #javascriptquiz #codingchallenge #javascriptshorts #javascriptwtf #weakreferences #javascriptbugs #advancedjavascript

https://www.youtube.com/watch?v=C_bVlNy3FMI

WeakMap REJECTS Primitive Keys?! #javascripttricks

YouTube
javascript weakmaps should be iterable — wingolog

wingolog: article: javascript weakmaps should be iterable

Literal #ShowerThought #idea: A #JavaScript "composite" #WeakMap. Returns a value for a given array of references. All weakly referenced to avoid memory leaks. Something like:

```
const map = new CompositeWeakMap();
const keys = [ {}, {}, {} ];

map.set(keys, 'test');
map.get(keys); // 'test'
```

Not 100% sure it's possible since `WeakMap` is only keyed by a single reference, but I think it's possible if you chain two `WeakMap` objects together. I have an implementation in my head, but I'll have to actually try it to see if it works for real. 🤔

Hiding Implementation Details with ECMAScript 6 WeakMaps

WeakMaps are a new feature in ECMAScript 6 that, among manyother things, gives us a new technique to hide private implementation data andmethods from consume...