#weakmap — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #weakmap, aggregated by home.social.
-
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
-
javascript weakmaps should be iterable
https://wingolog.org/archives/2024/08/19/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. 🤔