Unfortunately, because of the existence of non-unique Symbols (Symbol.for()) this won't come to ECMAScript :-/
So, the best options - as you mentioned - are new String() or object/class.
The latter with a ref property for better "debugability" and/or a toString() implementation (just an idea: debug info like the ref number could be held in a WeakMap if you want to hide it from the object, toString() could read from there)
Too bad, I'd have prefered Symbols to be allowed as WeakMap keys...
Yes, primarily I've been using a WeakMap to hold sensitive data (which shouldn't be altered by any other way than calling the API), but it could also hold debug info.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Ok, I agree with you that a
WeapMap
is fine here, and therefore it should IMHO be possible to have Symbols as WeakMap keys.I just found an interesting thread at github.com/tc39/ecma262/issues/1194 (TL;DR)
Unfortunately, because of the existence of non-unique Symbols (
Symbol.for()
) this won't come to ECMAScript :-/So, the best options - as you mentioned - are
new String()
or object/class.The latter with a
ref
property for better "debugability" and/or atoString()
implementation (just an idea: debug info like the ref number could be held in aWeakMap
if you want to hide it from the object, toString() could read from there)Indeed interesting thread!
Too bad, I'd have prefered Symbols to be allowed as WeakMap keys...
Yes, primarily I've been using a WeakMap to hold sensitive data (which shouldn't be altered by any other way than calling the API), but it could also hold debug info.