W3C home > Mailing lists > Public > public-script-coord@w3.org > January to March 2017

Re: Objects that can stringify in multiple ways

From: Anne van Kesteren <annevk@annevk.nl>
Date: Wed, 15 Mar 2017 19:35:40 +0100
Message-ID: <CADnb78jCQMOtxx5a8AMBq=ySiR3Dn1_yp4vNf=qH_u6vqXWkYQ@mail.gmail.com>
To: "Tab Atkins Jr." <jackalmage@gmail.com>
Cc: public-script-coord <public-script-coord@w3.org>
On Wed, Mar 15, 2017 at 7:29 PM, Tab Atkins Jr. <jackalmage@gmail.com> wrote:
> If you can come up with reasonable arguments differentiating the
> different ways (probably named, in an options object?), overloading
> toString() is reasonable. Number.toString() works well this way,
> because the "different ways of printing" are just different bases,
> covered by a single simple argument integer argument.
>
> But if the different ways are relatively different, I think it's
> better to instead just add different methods to the prototype, and
> bless one of them as the "default" way.

For URLs (and hosts, which might end up as URLHost) the main
difference we might want to expose is ASCII vs Unicode display. We
could indeed have

  obj.toString({as: "unicode"})

but this seems only better than

  obj.unicode()

if it brings some other benefits (in the future?) around
stringification as otherwise it's just a pretty verbose way of
expressing the same semantic.

I'm probably overthinking it.


-- 
https://annevankesteren.nl/
Received on Wednesday, 15 March 2017 18:36:10 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 15 March 2017 18:36:10 UTC