Implicit coercion of Symbols
claude.pache at gmail.com
Sun Jan 4 08:36:48 PST 2015
> Le 4 janv. 2015 à 03:18, Rick Waldron <waldron.rick at gmail.com> a écrit :
> On Sat Jan 03 2015 at 8:25:40 PM Brendan Eich <brendan at mozilla.org> wrote:
> Rick Waldron wrote:
> > That example above is pretty compelling for throw always consistency.
> With a new Reflect.* API for converting a symbol to its
> diagnostic/debugging string?
> If you agree, please file a bugs.ecmascript.org ticket.
I think that it is asking for the wrong consistency. There is another consistency to be wanted, namely:
String(sym) === sym.toString()
(assuming that `Symbol.prototype.toString` isn't sabotaged by user code, of course). Indeed:
* `String(sym)` and `sym.toString()` are *explicit* coercions to string; while
* `sym + ""` triggers an *implicit* coercion to string (in that very case, preceded by a coercion to primitive, but it's not the subject).
If there is a need to directly expose the implicit coercion to string operation to user code, `Reflect.toString()` is a natural fit for that, together with `Reflect.toBoolean()`, `Reflect.toPropertyKey()`, `Reflect.toPrimitive(_, hint)`, etc.
More information about the es-discuss