Symbols, Protocols, Frames, and Versioning

Tab Atkins Jr. jackalmage at gmail.com
Fri Oct 5 08:58:36 PDT 2012


On Fri, Oct 5, 2012 at 7:11 AM, Sam Tobin-Hochstadt <samth at ccs.neu.edu> wrote:
> Note also that `Symbol.for` has some really weird behavior. For
> example, what does this evaluate to?
>
>     Symbol.for("x") instanceof Symbol
>
> That depends if someone has previously evaluated `Symbol.for("x")` in
> a different frame.

This isn't weird at all.  It's "true" regardless of whether
Symbol.for("x") has been evaluated elsewhere.

Symbol.for("x") creates a Symbol with forgeability (so that other
frames can successfully forge the Symbol and buy into your API).  It
doesn't need to create identical objects, any more than String("x")
needs to create identical objects every time.  So long as every
instance of Symbol.for("x") can be interchanged as a property name,
you're fine.

(In your assumed behavior, Symbol.for() would still be an unpluggable
cross-frame messaging hole, contrary to Mark Miller's goals.  It would
be low bandwidth, of course (one bit per Symbol), but still.)

~TJ


More information about the es-discuss mailing list