Implicit coercion of Symbols

Brendan Eich brendan at mozilla.org
Fri Jan 2 16:53:18 PST 2015


Caitlin Potter wrote:
> One reason it might make sense to throw, is people converting values 
> to string names for use as object properties. Reason you'd want to 
> throw would be to prevent accidentally making the key useless 
> (different from its original Symbol value).

This is exactly the reason.

Of course, having String(x) and '' + x diverge is funky, but not novel:

js> o = {valueOf(){return 42}, toString(){return 'haha'}}
({valueOf:function valueOf(){return 42}, toString:function 
toString(){return 'haha'}})
js> String(o)
"haha"
js> ''+o
"42"

/be


More information about the es-discuss mailing list