You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Proxies ♥ WeakMaps. In our readOnlyView example, we create a new proxy every time an object is accessed. It could save a lot of memory to cache every proxy we create in a WeakMap, so that however many times an object is passed to readOnlyView, only a single proxy is created for it.
thrownewError("can't modify read-only view");}varhandler={// Override all five mutating methods.set: NOPE,defineProperty: NOPE,deleteProperty: NOPE,preventExtensions: NOPE,setPrototypeOf: NOPE};functionreadOnlyView(target){returnnewProxy(target,handler);}
This is one of the motivating use cases for WeakMap.
Because WeakMaps is confused with Maps, could be interesting add a section about when to use WeakMaps
The text was updated successfully, but these errors were encountered:
Reading about Proxies at
https://hacks.mozilla.org/2015/07/es6-in-depth-proxies-and-reflect/
I found a very nice WeakMaps usage example:
Because
WeakMaps
is confused withMaps
, could be interesting add a section about when to useWeakMaps
The text was updated successfully, but these errors were encountered: