Template site objects and WeakMap

Boris Zbarsky bzbarsky at mit.edu
Wed Jun 17 17:59:42 UTC 2015

On 6/17/15 1:54 PM, Jordan Harband wrote:
> Could I not use `Object(Symbol.for('some global registry symbol'))` as a
> `WeakMap` key? That would return a realm-specific object, of course.

Object(Symbol.for("x")) == Object(Symbol.for("x")) tests false.  That's 
because http://www.ecma-international.org/ecma-262/6.0/#sec-object-value 
reaches step 3 which lands you in 
http://www.ecma-international.org/ecma-262/6.0/#sec-toobject which 
returns a new Symbol object every time.

So while you _could_ use Object(Symbol.for('some global registry 
symbol')) as a weakmap key it would not be terribly useful unless you 
hung on to that object somewhere.


More information about the es-discuss mailing list