3 ms·
I think really you'd want to use `key in cache`, because ?? wouldn't let you memoize null or undefined. Although `in` possibly opens you up to prototype issues
by deergomoo 5y ago
I think really you'd want to use `key in cache`, because ?? wouldn't let you memoize null or undefined.
Although `in` possibly opens you up to prototype issues. JavaScript is a bundle of fun.
- jaffathecake 5y agoYeah, Map (or WeakMap if keys are objects and you don't need iteration) is much better at this kind of thing.
- k__ 5y agoGood point. Collection types are prevalent in languages like Java, but JS devs had to use plain objects for years.
- saurik 5y agoWhich is why you needed to build an actual data structure to do this kind of work based off checking for against the prototype chain instead of assuming you can use tiny bits of direct JavaScript operators.