My expectation would be that... (a === b) === (new Symbol(a) === new Symbol(b))
I.e., `new Symbol(a) === new Symbol(b)` iff `a === b`. This satisfies the strings/integers scenario, but, of course, fails your WeakMap garbage collection semantics. You need WeakSymbolMaps (+ this proposal) :) On Fri, Jul 12, 2013 at 4:15 PM, K. Gadd <[email protected]> wrote: > I would welcome (with fanfare and parades) a new Symbol(obj) that worked > for strings and integers. Such is not possible using the WeakMap shim > (you'd have to detect the type of the value and have multiple dictionaries, > or something, and you'd leak the symbols forever...) > > Of course, what that means is I'm asking for weakly cached symbols with > referential identity, which means it would allow detecting garbage > collections, so this is probably around the point where people chime in and > say it's not possible. Oh well. :( > > On Fri, Jul 12, 2013 at 12:42 PM, Jeremy Martin <[email protected]> wrote: > >> Good point, that's definitely a usable solution (also a better >> representation of what I was attempting to describe). >> >> I'd still be interested in a less-verbose/more-efficient approach using >> the Symbol constructor, but it may not be a common enough scenario to >> justify it when a workaround does exist. >> >> >> On Fri, Jul 12, 2013 at 3:32 PM, Allen Wirfs-Brock <[email protected] >> > wrote: >> >>> >>> On Jul 12, 2013, at 12:14 PM, Jeremy Martin wrote: >>> >>> In brief: allow Symbol's to be constructed with a single parameter, with >>> the following behavior: >>> >>> > var obj = {}; >>> undefined >>> > new Symbol({}) === new Symbol({}) >>> false >>> > new Symbol(obj) === new Symbol(obj) >>> true >>> >>> >>> You can use a WeakMap to build your own object-selected Symbol factory: >>> >>> let known = new WeakMap; >>> >>> function ObjSymFactory(obj) { >>> //handle obj === undefined however you want >>> let sym = known.get(obj); >>> If (!sym) { >>> sym = new Symbol; >>> known.set(obj,sym); >>> } >>> return sym; >>> } >>> >>> Allen >>> >>> >>> >> >> >> -- >> Jeremy Martin >> 661.312.3853 >> http://devsmash.com >> @jmar777 >> >> _______________________________________________ >> es-discuss mailing list >> [email protected] >> https://mail.mozilla.org/listinfo/es-discuss >> >> > -- Jeremy Martin 661.312.3853 http://devsmash.com @jmar777
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

