Creating a class that uses WeakMap to work with specific complex types

Just as with Map, knowing what type to expect from the WeakMap collection can be valuable. The key types are very slightly restricted, but still pretty loose, and there is no restriction on what type the values can be.

In this recipe, we'll take a look at how to create a wrapper class for WeakMap in order to control what types are used in the WeakMap.

Get ECMAScript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.