Default @@toStringTag for user classes

Andrea Giammarchi andrea.giammarchi at gmail.com
Tue Dec 2 09:56:26 PST 2014


I think by `@@toStringTag` he meant the ability to define a `[[Class]]`
name so that `{}.toString.call(generic)` would return such name instead of
`Object` but I'm sure Dmitry will come back explaining and/or asking more.

On Tue, Dec 2, 2014 at 4:49 PM, Claude Pache <claude.pache at gmail.com> wrote:

>
> > Le 2 déc. 2014 à 08:46, Dmitry Soshnikov <dmitry.soshnikov at gmail.com> a
> écrit :
> >
> > Hi,
> >
> > Probably worth providing a default implementation of the `@@toStringTag`
> when evaluating a class [1]. In this case users will be able to do:
> >
> > ```
> > class Point { ... }
> >
> > var p = new Point(1, 2);
> > console.log(p); // "[object Point]"
> > ```
>
> You seem to imply that  `console.log(p)` will show the result of
> `p.toString()` in the console. But it is not the case for the majority of
> browsers.
>
> I've just tried:
>
> ```
> var Point = function() {}
> Point.prototype.toString = function() { return "(this is an object of type
> Point)" }
> console.log(new Point)
> ```
>
> Results are:
>
> Firefox: Object { }
> Chrome: Point{toString: function}
> Safari: Object
> IE: [object Object]    (this is an object of type Point)
>
> In particular, note that Chrome doesn't need the help of `.toString()` in
> order to log useful information.
>
> —Claude
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20141202/d6716806/attachment.html>


More information about the es-discuss mailing list