Comments on Sept Meeting Notes

Allen Wirfs-Brock allen at wirfs-brock.com
Fri Sep 27 08:28:42 PDT 2013


On Sep 27, 2013, at 7:52 AM, Erik Arvidsson wrote:

> What's the use case for Symbol.keyFor?
> 

The use case was actually suggested in a response to dherman earlier in this thread when he mentioned sharing symbols between workers.

If you need to serialize an object with symbol keyed properties you need to convert the symbol into sometime that can be equivalently recreated on the other side of the serialization barrier.  For a registered Symbol the obvious way to do this is via its registration name:

Symbol.toJSON = function() {
       let key = Symbol.keyFor(lthis);
       if (key === undefined) return null;  //unregistered symbols can't be serialized in this example
       return "**Symbol:"+key;
}


The deserializer would have to do a pass over the resulting objects replace=ing "**Symbol:..." property names with the locally register Symbol under the same key.

Allen


More information about the es-discuss mailing list