Implementing an identical JSON.stringify
Claude Pache
claude.pache at gmail.com
Sat Aug 4 22:35:14 UTC 2018
> Le 5 août 2018 à 00:16, Michael Theriot <michael.lee.theriot at gmail.com> a écrit :
>
> `JSON.stringify` has unintuitive behavior regarding interal slots.
I don’t think that anything involving an object that has a [[StringData]] internal slot but has `Number.prototype` in its prototype chain could have an ”intuitive” behaviour...
>
>
> I think this is related to `Array.isArray`. Is there an equivalent `Number.isNumber`? Or is this just something only `JSON.stringify` can do?
Try `Number.prototype.valueOf.call(obj)`: it will throw a TypeError if and only if `obj` has no [[NumberData]] internal slot. Ditto for String, Boolean and Symbol.
—Claude
More information about the es-discuss
mailing list