From 5aebb8960a259a4e0c99b47b2e914cda3026c9a8 Mon Sep 17 00:00:00 2001 From: Vse Mozhe Buty Date: Sun, 29 Nov 2020 18:19:28 +0200 Subject: [PATCH] Fix typos in 1.5.8 (WeakMap and WeakSet) --- 1-js/05-data-types/08-weakmap-weakset/article.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/1-js/05-data-types/08-weakmap-weakset/article.md b/1-js/05-data-types/08-weakmap-weakset/article.md index 6c3a2828..b5d98c46 100644 --- a/1-js/05-data-types/08-weakmap-weakset/article.md +++ b/1-js/05-data-types/08-weakmap-weakset/article.md @@ -207,7 +207,7 @@ alert(cache.size); // 1 (Ouch! The object is still in cache, taking memory!) For multiple calls of `process(obj)` with the same object, it only calculates the result the first time, and then just takes it from `cache`. The downside is that we need to clean `cache` when the object is not needed any more. -If we replace `Map` with `WeakMap`, then this problem disappears. The cached result will be removed from memory automatically after the object gets garbage collected . +If we replace `Map` with `WeakMap`, then this problem disappears. The cached result will be removed from memory automatically after the object gets garbage collected. ```js run // 📁 cache.js @@ -284,7 +284,8 @@ The most notable limitation of `WeakMap` and `WeakSet` is the absence of iterati `WeakSet` is `Set`-like collection that stores only objects and removes them once they become inaccessible by other means. -It's main advantages are that they have weak reference to objects, so they can easily be removed by garbage colector. -That comes at the cost of not having support for `clear`, `size`, `keys`, `values` ... +Their main advantages are that they have weak reference to objects, so they can easily be removed by garbage colector. + +That comes at the cost of not having support for `clear`, `size`, `keys`, `values`... `WeakMap` and `WeakSet` are used as "secondary" data structures in addition to the "primary" object storage. Once the object is removed from the primary storage, if it is only found as the key of `WeakMap` or in a `WeakSet`, it will be cleaned up automatically.