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

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.

主站蜘蛛池模板: 政和县| 封开县| 通海县| 康保县| 东山县| 吴江市| 鸡东县| 玉田县| 甘德县| 土默特右旗| 额济纳旗| 临西县| 五指山市| 石楼县| 白河县| 武定县| 松滋市| 沙雅县| 泽州县| 连平县| 潞城市| 汨罗市| 双江| 和林格尔县| 南宁市| 濮阳市| 五指山市| 普定县| 抚顺县| 锦州市| 绥德县| 吴旗县| 五指山市| 遵义县| 奉节县| 郁南县| 辉县市| 嘉禾县| 蛟河市| 开封市| 海原县|