What are Symbols? Objects? New primitive type?

Andreas Rossberg rossberg at google.com
Sat Apr 13 06:25:40 PDT 2013


On 13 April 2013 13:36, Claude Pache <claude.pache at gmail.com> wrote:
>
>
> Le 13 avr. 2013 à 09:56, Andreas Rossberg <rossberg at google.com> a écrit :
>
>> On 13 April 2013 00:35, Allen Wirfs-Brock <allen at wirfs-brock.com> wrote:
>>> <snip>
>>>
>>> Regarding #3
>>>
>>> The biggest footgun is if
>>>  new Symbol()
>>> creates a Symbol wrapper.  However,
>>>  new Symbol()
>>> returning a primitive values would be unlike anything we currently have in
>>> the language
>>
>> I agree, it has to be the former. But what footgun are you seeing
>> there? Any attempt to use a wrapper as a key throws under the
>> agreed-upon semantics, so I don't see the issue.
>
> As a JS programmer, I will be very tempted to write `new Symbol` to get a new symbol. The issue is that you get an error in a different line of code from where the problem lies, and you have to be fond of the subtle distinction between value and object wrapper (which is a feature we never use in our daily coding) to understand what is happening without external help.

While that is true, and unfortunate, it also is the case for pretty
much every other mistake you can make in JavaScript (or any dynamic
language, for that matter) -- and there are far more subtle ones in
that class. So I'm not convinced that this particular case justifies
special casing.

/Andreas


More information about the es-discuss mailing list