我一直在用
JavaScript工作
WeakMaps,在检查文档后我意识到明确的方法是
deprecated / removed from ECMAScript 6.
@H_502_2@这是什么原因?
为什么强迫我们做一个明确的功能,如:
为什么强迫我们做一个明确的功能,如:
clear() { this._weakmap = new WeakMap() }
解决方法
@H_502_2@“The mapping from weakmap/key pair value can only be observed or@H_502_2@Mark Miller @H_502_2@这种限制的原因是安全问题:
affected by someone who has both the weakmap and the key. With
clear(),someone with only the WeakMap would’ve been able to affect
the WeakMap-and-key-to-value mapping.”
@H_502_2@A key property of Weak Maps is the inability to enumerate their keys.@H_502_2@tc39wiki @H_502_2@可枚举的WeakMap也可能影响GC,因为您可以间接观察GC过程.因此,为了确保可预测的设计,也清除了清晰.
This is necessary to prevent attackers observing the internal behavior
of other systems in the environment which share weakly-mapped objects.
Should the number or names of items in the collection be discoverable
from the API,even if the values aren’t,WeakMap instances might
create a side channel where one was prevIoUsly not available.