Reflect.toStringSpec proposal

Bergi a.d.bergi at
Wed Dec 14 03:44:09 UTC 2016

Sergey R schrieb:
> I want to propose a new language feature — Reflect.toStringSpec.

`Reflect.toString` or `Reflect.toStringSpec`?

> Here is a repo

| Rationale
| There is no exact way to call spec's `ToString` in JS.
| However it may be necessary for polyfills.

It's not that hard to emulate, is it? There are other internal 
operations would be more important.

Regardless, the `Reflect` namespace is supposed to only contain object 
tools that would be the default for proxy traps. No `ToString` in there.

| Current solution is to do something like:
| function toStringSpec(target) {
|    return target == null ? target : String(Object(target));
| }

That looks horribly wrong. It doesn't do the least what `ToString` does 
in ES6.

The spec says it should do
function ToString(x) {
     if (typeof x != "symbol) return String(x);
     else throw new TypeError("…");
This would be a pretty standard approach, also being used e.g. in

And if you don't care about Symbols, you can easily just use `String`.

Kind regards,

More information about the es-discuss mailing list