Implicit coercion of Symbols

Andrea Giammarchi andrea.giammarchi at gmail.com
Sat Jan 3 15:30:43 PST 2015


Agreed with Brendan,
  and I've  thought the same.

It's been also years we have problems using unknonw objects in the wild,
i.e.

```js
var n = {__proto__:null};
var s = String(n); // error, No default value
var s = '' + n; // error, No default value
```
Same if used as [property accessor] so I am not sure why `String(o)` when
`o` is `Symbol` should not throw.

I'd expect it to throw all the time and let developers be a bit more
careful on their explicit or implicit casts.

The `toString` and `valueOf` are great examples that could compromise a lot
of real-world code.

Being `Symbols` new we should probably/hopefully get them in the right way.

I feel like throwing either cases is the right way.

Just my thoughts,
  Best Regards





On Sat, Jan 3, 2015 at 11:56 PM, Brendan Eich <brendan at mozilla.org> wrote:

> Rick Waldron wrote:
>
>> Subjectively: I think it's nice in theory, but bad in practice.
>>
>
> Compared to what? Converting a symbol to asilent-but-deadly string?
>
> I thought you were gonna raise the other way to restore consistency: make
> String(sym) throw too. Then we'd need a new Reflect op to get a string from
> a symbol.
>
> /be
>
> _______________________________________________
> 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/20150104/4d5a1b49/attachment.html>


More information about the es-discuss mailing list