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
Copy file name to clipboardExpand all lines: 1-js/05-data-types/07-map-set-weakmap-weakset/article.md
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -324,7 +324,7 @@ Now where do we need such thing?
324
324
The idea of `WeakMap` is that we can store something for an object that exists only while the object exists. But we do not force the object to live by the mere fact that we store something for it.
325
325
326
326
```js
327
-
weakMap.put(john, "secret documents");
327
+
weakMap.set(john, "secret documents");
328
328
// if john dies, secret documents will be destroyed
329
329
```
330
330
@@ -378,7 +378,7 @@ With a regular `Map`, cleaning up after a user has left becomes a tedious task:
378
378
`WeakSet` behaves similarly:
379
379
380
380
- It is analogous to `Set`, but we may only add objects to `WeakSet` (not primitives).
381
-
- An object exists in the set while it has reachable from somewhere else.
381
+
- An object exists in the set while it is reachable from somewhere else.
382
382
- Like `Set`, it supports `add`, `has` and `delete`, but not `size`, `keys()` and no iterations.
383
383
384
384
For instance, we can use it to keep track of whether an item is checked:
@@ -429,4 +429,4 @@ The most notable limitation of `WeakMap` and `WeakSet` is the absence of iterati
429
429
430
430
- Also does not support `size/clear()` and iterations.
431
431
432
-
`WeakMap` and `WeakSet` are used as "secondary" data structures in addition to the "main" object storage. Once the object is removed from the main storage, so it only stays in `WeakMap/WeakSet`, they clean up automatically.
432
+
`WeakMap` and `WeakSet` are used as "secondary" data structures in addition to the "main" object storage. Once the object is removed from the main storage, if it is only found in the `WeakMap/WeakSet`, it will be cleaned up automatically.
0 commit comments