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

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

Here is a repo https://github.com/chicoxyzzy/proposal-reflect-tostringspec

| 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 https://github.com/ljharb/es-abstract/blob/035153777213981e0e24f6cf007ffbd279384130/es6.js#L129-L135

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

Kind regards,
 Bergi
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to