Standard builtins' prototypes and toString
C. Scott Ananian
ecmascript at cscott.net
Thu Jun 12 09:55:55 PDT 2014
On Thu, Jun 12, 2014 at 12:48 PM, Jason Orendorff
<jorendorff at mozilla.com> wrote:
> In any case, I doubt we have a choice. ES3-5 at least supported it. There is
> surely a Web page somewhere that calls .toString() on every object it can
> find, just because.
If you are concerned about compatibility, them
`Date.prototype.toString()` should return "Invalid Date" (as Erik
stated, in concrete pseudo-code, above), not the result of
`Object.prototype.toString()`. Similarly,
`Boolean.prototype.toString()` should return `false`, etc.
If we're changing the result of `#toString`, then we should just throw
a `TypeError`, rather than return some arbitrary value. Specifically,
I want `Date#toString` to consistently throw a `TypeError` if `this`
is not a `Date` (or subclass), not to do some weird special case only
for `Date.prototype`.
--scott
More information about the es-discuss
mailing list