String(symbol)

Rick Waldron waldron.rick at gmail.com
Wed Aug 13 09:28:01 PDT 2014


On Wed, Aug 13, 2014 at 11:45 AM, Nathan Wall <wwall at google.com> wrote:

> Out of mere curiosity, why is it desired that `symbol + ''` throw?
>
>
Relevant discussion:

https://github.com/rwaldron/tc39-notes/blob/c9742738ec3577d5158e8b8bfe3a46be596fef0b/es6/2013-03/mar-14.md#46-symbols


Rick


> Nathan
>
>
>
> On Tue, Aug 12, 2014 at 10:39 PM, Erik Arvidsson <erik.arvidsson at gmail.com
> > wrote:
>
>> symbol + '' must continue to throw.
>>
>> I was suggesting that String(symbol) should not throw.
>>
>> This can be spec'ed as String( value ) checking the Type of the value and
>> special case it in case of the value being a symbol.
>>
>>
>> On Tue, Aug 12, 2014 at 5:17 PM, Claude Pache <claude.pache at gmail.com>
>> wrote:
>>
>>>
>>> Le 12 août 2014 à 22:35, Erik Arvidsson <erik.arvidsson at gmail.com> a
>>> écrit :
>>>
>>> Right now String(symbol) throws because it uses ToString which is
>>> spec'ed to throw.
>>>
>>> I'm suggesting that we special case String(value) to do a type check for
>>> Symbol and return the same string as Symbol.prototype.toString.call(value)
>>> does.
>>>
>>>
>>> https://people.mozilla.org/~jorendorff/es6-draft.html#sec-string-constructor-string-value
>>>
>>> The motivation for this is that String(value) is pretty explicit and was
>>> in ES5 a safer way to stringify something than value.toString().
>>>
>>> --
>>> erik
>>>
>>>
>>> +1. As I already noted last year [1], as currently specced, ad-hoc
>>> debugging code like `alert("got argument: " + x)` or `alert("got argument:
>>> " + String(x))` will throw for symbols, while `alert("got argument: " +
>>> x.toString())` will throw for `null`, `undefined`, and
>>> `Object.create(null)`.
>>>
>>> [1] http://esdiscuss.org/topic/a-new-es6-draft-is-available#content-11
>>>
>>>
>>>
>>
>>
>> --
>> erik
>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140813/2a5a6be5/attachment.html>


More information about the es-discuss mailing list