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

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.

主站蜘蛛池模板: 仙游县| 二连浩特市| 莱芜市| 东阳市| 印江| 娄烦县| 夏河县| 武清区| 正宁县| 博爱县| 富锦市| 沙雅县| 扶绥县| 中超| 桑日县| 咸宁市| 平凉市| 乌拉特后旗| 宁陕县| 肃宁县| 临武县| 唐海县| 双鸭山市| 民乐县| 林西县| 溧水县| 望江县| 英山县| 内丘县| 卢湾区| 喀什市| 荥经县| 绥德县| 霍林郭勒市| 钟祥市| 泰州市| 贵溪市| 涟源市| 公主岭市| 合阳县| 吉木乃县|