@firefoxwebdevs@mastodon.social
2026-04-16 13:23 UTC
map.getOrInsertComputed is newly baseline! It's a small feature, but I've found it pretty useful. Here's how it works.
Full docs and polyfills on MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/getOrInsertComputed
Replies (1)
-
@loucyx@mastodon.social 2026-04-16 14:47
@firefoxwebdevs@mastodon.social I have a memo library and I used to have a “hack” for this: return (map.has(key) ? map : map.set(key, computeValue()).get(key); My code is so much cleaner now: return map.getOrInsertComputed(key, computeValue); I love this feature 💖