Implicit coercion of Symbols

Caitlin Potter caitpotter88 at gmail.com
Fri Jan 2 15:37:50 PST 2015


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).

Haven't paid attention to the rationale, but that doesn't seem like a bad one.

> On Jan 2, 2015, at 6:26 PM, Rick Waldron <waldron.rick at gmail.com> wrote:
> 
> Kyle Simpson brought this up on Twitter today and I think it deserves one last look. Here's an example of the issue: 
> 
>   var sym = Symbol("description");
>   sym + ""; // Throws
> 
> Meanwhile...
> 
>   var sym = Symbol("description");
>   String(sym); // "Symbol(description)" *
> 
> 
> (* appears to be the convention that implementors have converged on)
> 
> This is the only time that a "thing" in JavaScript throws when it encounters an implicit coercion operation. This detail appears to be problematic in that it's an unnecessary divergence from the language's normal behaviour. 
> 
> Ref: https://people.mozilla.org/~jorendorff/es6-draft.html#sec-addition-operator-plus-runtime-semantics-evaluation 11.a 
> 
> 
> Rick
> _______________________________________________
> 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/20150102/1fbf4589/attachment.html>


More information about the es-discuss mailing list