Interface prototype objects and ES6 @@toStringTag

Allen Wirfs-Brock allen at wirfs-brock.com
Mon May 13 14:01:31 PDT 2013


On May 13, 2013, at 1:50 PM, Erik Arvidsson wrote:

> The way that WebIDL require Object.prototype.toString to return "[object TypePrototype]" for the interface prototype object and "[object Type]" for the instances seems to imply that every instance needs to have an own @@toStringTag.
> 
> http://people.mozilla.org/~jorendorff/es6-draft.html#sec-15.2.4.2
> http://dev.w3.org/2006/webapi/WebIDL/#es-environment
> 
> If an instance does not have its own @@toStringTag, Object.prototype.toString will read through to the [[Prototype]] which would return the wrong string.

Well, toString just does a [[Get]] for @@toStringTag.  You are perfectly free to implement it as a get accessor that takes into account whether the this value is an instance or a prototype object. Not sure whether the complexity is really worth it in most cases. I considered building something like that into Object.prototype.toString but it seemed hard to justify and there was no (ES) legacy reason for doing so.

The preferred way to over-ride toString should be via a toString method, not via @@toStringTag. 

Allen


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130513/cd19bb93/attachment.html>


More information about the es-discuss mailing list