archives

« Bugzilla Issues Index

#3857 — Add String.prototype[@@toStringTag] and other pre-ES6 constructors' toStringTag property


By letting
Array.prototype[@@toStringTag] = 'Array',
String.prototype[@@toStringTag] = 'String',
Function.prototype[@@toStringTag] = 'Function',
Error.prototype[@@toStringTag] = 'Error',
Boolean.prototype[@@toStringTag] = 'Boolean',
Number.prototype[@@toStringTag] = 'Number',
Date.prototype[@@toStringTag] = 'Date',
RegExp.prototype[@@toStringTag] = 'RegExp,
we are able to simplify Object.prototype.toString's algorithm and make constructor.prototype[@@toStringTag] more consistent.

What's more, it can also preserve compatibility for pre-ES6 codes, since most prototypes are now ordinary objects.
In ES5:
Object.prototype.toString.call(String.prototype) == '[object String]'
In current ES6 spec:
Object.prototype.toString.call(String.prototype) == '[object Object]'
After my proposal:
Object.prototype.toString.call(String.prototype) == '[object String]'


the final design for Object.prototype.toString was settled at the Jany 2015 TC39 meeting https://github.com/tc39/tc39-notes/blob/master/es6/2015-01/jan-28.md#45-tostringtag