W3C home > Mailing lists > Public > public-script-coord@w3.org > April to June 2013

Re: Interface prototype objects and ES6 @@toStringTag

From: Erik Arvidsson <erik.arvidsson@gmail.com>
Date: Mon, 13 May 2013 17:44:08 -0400
Message-ID: <CAJ8+GogRoo1kyUAXzHVhwQYrLLfOn2nQNDU5diC11HvY_14qxw@mail.gmail.com>
To: Kevin Reid <kpreid@google.com>
Cc: Allen Wirfs-Brock <allen@wirfs-brock.com>, "public-script-coord@w3.org" <public-script-coord@w3.org>, es-discuss <es-discuss@mozilla.org>
Kevin: Node.prototype.toString is never invoked when you do

I understand that no one has complained. Browser differ in this area today
so applications have to be careful of they ever try to get the [[Class]] of

On Mon, May 13, 2013 at 5:12 PM, Kevin Reid <kpreid@google.com> wrote:

> On Mon, May 13, 2013 at 2:01 PM, Allen Wirfs-Brock <allen@wirfs-brock.com>wrote:
>> 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-
>> 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.
> FWIW, oddball implementor's experience:
> In Caja's emulated DOM type hierarchy, Node.prototype.toString is an
> ordinary method which searches the prototype chain for the appropriate
> type-name, including distinguishing prototypes. This seems to work fine
> insofar as it gives the answers I want it to give and nobody's ever
> complained, and I think it's identical in abilities and effects to your
> proposal of an @@toStringTag accessor.

Received on Monday, 13 May 2013 21:44:56 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:13 UTC