3 ms·
Interesting how this author uses WeakSet where a normal set would be completely equivalent; as long as the function is running, the toplevel object is reachable
by tomp 12y ago
Interesting how this author uses WeakSet where a normal set would be completely equivalent; as long as the function is running, the toplevel object is reachable from the local variables, and so are all the "deep" objects, by definition (they belong to the toplevel object's reference graph). Therefore, there is no way that an object becomes unreachable after it has been visited by the algorithm (considering that JavaScript is single-threaded). The only reason I can see for this is if JavaScript has no normal sets.
- kevingadd 12y agoJS has Set and WeakSet, and Set is more powerful (it allows a wider variety of key types). It's actually quite rare for you to need a WeakSet.