官术网_书友最值得收藏!

Creating a stack

Now that we know when and why we would want to use a stack, let's move on to implementing one. As discussed in the preceding section, we will use a WeakMap() for our implementation. You can use any native data type for your implementation, but there are certain reasons why WeakMap() would be a strong contender. WeakMap() retains a weak reference to the keys that it holds. This means that once you are no longer referring to that particular key, it gets garbage-collected along with the value. However, WeakMap() come with its own downsides: keys can only be nonprimitives and are not enumerable, that is, you cannot get a list of all the keys, as they are dependent on the garbage collector. However, in our case, we are more concerned with the values that our WeakMap() holds rather than keys and their internal memory management.

主站蜘蛛池模板: 武陟县| 宁明县| 五家渠市| 朝阳县| 元氏县| 尖扎县| 宁陕县| 吴川市| 鲁甸县| 南安市| 呈贡县| 福建省| 泾川县| 建德市| 沙雅县| 洪泽县| 天全县| 土默特左旗| 鄂托克旗| 湘阴县| 杂多县| 武清区| 鄂伦春自治旗| 双峰县| 昌江| 桦南县| 平阳县| 贺州市| 黔西县| 铜川市| 肃南| 格尔木市| 福泉市| 应城市| 淮南市| 长治县| 河间市| 凉山| 临邑县| 福州市| 阜康市|