How to iterate over a weakmap?

后端 未结 2 1189
忘了有多久
忘了有多久 2020-12-11 00:09

A javascript WeakMap ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap ) does not allow you to get the key, or the length or size, b

相关标签:
2条回答
  • 2020-12-11 00:50

    Things are moving and it will soon be possible to create iterable week maps thanks to weak refs. See the iterable WeakMap example in the tc39 weakrefs proposal.

    (note that it is already possible with nodejs v12.?.? using --harmony-weak-refs flag)

    0 讨论(0)
  • 2020-12-11 01:02

    Is it possible to nevertheless loop over entries in some way?

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

    If not … how does the Chrome console do this?

    The console uses the debugging API of the JS engine, which allows access to the internals of objects (also to promise states, wrapped primitives, etc.) and many more.

    0 讨论(0)
提交回复
热议问题