如何在ES6中使弱映射或弱映射可迭代? [重复]

时间:2022-09-06 20:24:50

This question already has an answer here:

这个问题在这里已有答案:

How to make weak set or weak map "iterable" in ES6 so that i can use for in loop :

如何在ES6中使弱集或弱映射“迭代”,以便我可以用于循环:

for(item in weakMap){console.log(item); }

1 个解决方案

#1


2  

No the contents of a WeakMap are not accessible by design, and there is no iterability.

没有设计无法访问WeakMap的内容,也没有可迭代性。

A key property of Weak Maps is the inability to enumerate their keys. 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.

弱地图的一个关键属性是无法枚举其键。这对于防止攻击者观察共享弱映射对象的环境中其他系统的内部行为是必要的。如果集合中的项目的数量或名称可以从API中发现,即使值不是这样,WeakMap实例也可能创建一个以前不可用的侧面通道。

Source

#1


2  

No the contents of a WeakMap are not accessible by design, and there is no iterability.

没有设计无法访问WeakMap的内容,也没有可迭代性。

A key property of Weak Maps is the inability to enumerate their keys. 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.

弱地图的一个关键属性是无法枚举其键。这对于防止攻击者观察共享弱映射对象的环境中其他系统的内部行为是必要的。如果集合中的项目的数量或名称可以从API中发现,即使值不是这样,WeakMap实例也可能创建一个以前不可用的侧面通道。

Source