Reflect.toStringSpec proposal

Jordan Harband ljharb at gmail.com
Wed Dec 14 05:24:07 UTC 2016


This was also pointed out to me elsewhere:

```js
const ToStringSpec = x => `${x}`;
```

On Tue, Dec 13, 2016 at 9:05 PM, Jordan Harband <ljharb at gmail.com> wrote:

> Here you go: `require('es-abstract').ToString` https://www.npmjs.
> com/package/es-abstract
>
> On Tue, Dec 13, 2016 at 7:44 PM, Bergi <a.d.bergi at web.de> wrote:
>
>> 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/035153777213981e0
>> e24f6cf007ffbd279384130/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
>> 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/20161213/1a57e0a8/attachment.html>


More information about the es-discuss mailing list