This repository was archived by the owner on May 16, 2025. It is now read-only.

Description
As #21 discussion, symbol as weakmap key have some arguments on registered symbols, both sides seems have good reasons, maybe we should find some tradeoffs which could satisfy both. I think the root cause of the issues is "symbol as weakmap keys" is too general, as I understand, the main use case is sharable identity, which do not need to be such general. Instead, we could introduce a much limited API:
Symbol.of(object) create the identity symbol for the object
get Symbol.prototype.object return the object of the identity symbol (return undefined for non-identity symbols)
Usage:
const obj = {}
const sym = Symbol.of(obj)
assert(symbol.object === obj)
Identity symbols (special symbol which ref to the object) would be somewhat like registered symbols (special symbol which ref to the string), so I expect it won't have much troubles to implement.
Note, such API is similar to Object.createSharableIdentity() idea except it use symbol for identity instead of frozen empty object.