weakmap

Why will ES6 WeakMap's not be enumerable?

南笙酒味 提交于 2020-01-09 07:15:29
问题 Before my re-entry in JavaScript (and related) I've done lots of ActionScript 3 and there they had a Dictionary object that had weak keys just like the upcoming WeakMap; but the AS3 version still was enumerable like a regular generic object while the WeakMap specifically has no .keys() or .values() . The AS3 version allowed us to rig some really interesting and usefull constructs but I feel the JS version is somewhat limited. Why is that? If the Flash VM could do it then what is keeping

Why will ES6 WeakMap's not be enumerable?

笑着哭i 提交于 2020-01-09 07:15:01
问题 Before my re-entry in JavaScript (and related) I've done lots of ActionScript 3 and there they had a Dictionary object that had weak keys just like the upcoming WeakMap; but the AS3 version still was enumerable like a regular generic object while the WeakMap specifically has no .keys() or .values() . The AS3 version allowed us to rig some really interesting and usefull constructs but I feel the JS version is somewhat limited. Why is that? If the Flash VM could do it then what is keeping

Would a “circular” reference be treated as “reachability” for a WeakMap?

一世执手 提交于 2019-12-21 09:29:10
问题 function f() { const w = new WeakMap(); const o = {}; w.set(o, { v: o }); return w; } const weakMap = f(); For the given code, would the only weakMap item considered as reachable or not? Hence, will it be garbage collected or not? PS: This question is asked from the perspective of the specification, not particular implementations. 回答1: Quoting WeakMap Objects section, If an object that is being used as the key of a WeakMap key/value pair is only reachable by following a chain of references

Would a “circular” reference be treated as “reachability” for a WeakMap?

拈花ヽ惹草 提交于 2019-12-21 09:28:02
问题 function f() { const w = new WeakMap(); const o = {}; w.set(o, { v: o }); return w; } const weakMap = f(); For the given code, would the only weakMap item considered as reachable or not? Hence, will it be garbage collected or not? PS: This question is asked from the perspective of the specification, not particular implementations. 回答1: Quoting WeakMap Objects section, If an object that is being used as the key of a WeakMap key/value pair is only reachable by following a chain of references

How to iterate over a weakmap?

房东的猫 提交于 2019-12-18 05:39:04
问题 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, by design. Is it possible to nevertheless loop over entries in some way ? If not .. how does the Chrome console do this ? 回答1: 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

What's the difference between ES6 Map and WeakMap?

馋奶兔 提交于 2019-12-17 07:04:29
问题 Looking this and this MDN pages it seems like the only difference between Maps and WeakMaps is a missing "size" property for WeakMaps. But is this true? What's the difference between them? 回答1: From the very same page, section "Why Weak Map?": The experienced JavaScript programmer will notice that this API could be implemented in JavaScript with two arrays (one for keys, one for values) shared by the 4 API methods. Such an implementation would have two main inconveniences. The first one is an

What's the difference between ES6 Map and WeakMap?

六月ゝ 毕业季﹏ 提交于 2019-12-13 02:43:40
问题 Looking this and this MDN pages it seems like the only difference between Maps and WeakMaps is a missing "size" property for WeakMaps. But is this true? What's the difference between them? 回答1: From the very same page, section "Why Weak Map?": The experienced JavaScript programmer will notice that this API could be implemented in JavaScript with two arrays (one for keys, one for values) shared by the 4 API methods. Such an implementation would have two main inconveniences. The first one is an

JavaScript WeakMap keep referencing gc'ed objects

时间秒杀一切 提交于 2019-12-04 03:36:21
问题 I am experiencing with JavaScript weakmaps, after trying this code in google chrome developer console, running with --js-flags="--expose-gc", I don't understand why the weakmap keep having a reference to a.b if a is gc'ed. var a = {listener: function(){ console.log('A') }} a.b = {listener: function(){ console.log('B') }} var map = new WeakMap() map.set(a.b, []) map.set(a, [a.b.listener]) console.log(map) // has both a and a.b gc() console.log(map) // still have both a and a.b a = undefined gc

JavaScript WeakMap keep referencing gc'ed objects

£可爱£侵袭症+ 提交于 2019-12-01 18:54:51
I am experiencing with JavaScript weakmaps, after trying this code in google chrome developer console, running with --js-flags="--expose-gc", I don't understand why the weakmap keep having a reference to a.b if a is gc'ed. var a = {listener: function(){ console.log('A') }} a.b = {listener: function(){ console.log('B') }} var map = new WeakMap() map.set(a.b, []) map.set(a, [a.b.listener]) console.log(map) // has both a and a.b gc() console.log(map) // still have both a and a.b a = undefined gc() console.log(map) // only have a.b: why does still have a reference to a.b? Should'nt be erased? In

How to iterate over a weakmap?

随声附和 提交于 2019-11-29 09:15:47
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, by design. Is it possible to nevertheless loop over entries in some way ? If not .. how does the Chrome console do this ? 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