Is there anything like JavaScript's WeakMap class in Nim?
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap
Nim does not have weak references, per se.
There's ptr and {.cursor.} but those aren't quite the same thing.
What's a weakmap useful for?
The only place I've ever used found use for weak maps and weak references is for opportunistic caches - when I want to be able to access an object by key only as long as it's already in use ; In a regular map, putting it inside the map would add another reference.
The way Python implements it (and I guess others to) is that weak references put themselves in a global dictionary (indexed by object ptr). A destructor, when it is called for object X, modifies all relevant weak references from X to None (python's nil), and only then actually destroys it.
Actually using a weak reference makes another real reference to it, of course.
I don't think it's possible in Nim without inheriting from a "Weakrefable" object, or at least one whose destructor can be hooked to clean-up the weak references.
Implementing weak references can be done like so: https://github.com/nim-lang/Nim/blob/devel/tests/gc/weakrefs.nim
Of course, there are other implementations possible, esp with destructors.