Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Discussion with TC39 about the semantics of sym...

dherman
September 18, 2013

Discussion with TC39 about the semantics of symbols

I presented these slides to TC39 in Sept 2013 to lead a discussion about the semantics of ES6 symbols.

dherman

September 18, 2013
Tweet

More Decks by dherman

Other Decks in Programming

Transcript

  1. 1. STATELESSNESS • Sharing a symbol should not share state.

    • Encapsulates a property key and nothing else.
  2. 4. MUTABLE PROTOTYPES Yes, monkey-patching in general is bad. But

    monkey-patching standard methods is a best practice. The evolution of the Web platform depends on it.
  3. •JS already has an answer for this! •typeof iterator ===

    "symbol" •Get/call operations auto-wrap •Prototype state is global per-frame •Sending across frames doesn’t share state
  4. • I know people think auto-wrapping is gross. • Here’s

    my positive spin: • Provides a uniform OO surface for all values. • Does so without ruining value immutability. • Does so without ruining API patchability. • Going forward: we need a solution for value types. YES, I DO SEE THAT ELEPHANT
  5. FOOTGUNS? [[ToPropertyKey]] of Symbol objects: auto- unwrap? Does it really

    matter in practice? Worry about toString for symbols and Symbol objects? Again, does it matter in practice?
  6. EXTENDING TYPEOF Do we know it won’t break the Web?

    MSIE "unknown" type may simply be rare enough to be undiscovered. Fallback: "object" with [[Get]] et al that behave like auto-wrappers? (plus Object.isValue()?)
  7. 18 SEPT 13 TC39 RESOLUTIONS • Yes to primitives with

    auto-wrapping • No auto-unwrapping of Symbol objects •typeof iterator === "symbol" • Symbol.prototype.toString should throw to help catch bugs in code evolution; Object.prototype.toString usable for infallible string coercion • Symbol() creates primitive, new Symbol throws