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

RE: Objects that can stringify in multiple ways

From: Domenic Denicola <d@domenic.me>
Date: Wed, 15 Mar 2017 20:52:23 +0000
To: Anne van Kesteren <annevk@annevk.nl>, public-script-coord <public-script-coord@w3.org>
Message-ID: <BY2PR05MB1959A9C13672F2BE380521E0DF270@BY2PR05MB1959.namprd05.prod.outlook.com>
From: Anne van Kesteren [mailto:annevk@annevk.nl] 

> URLs represent a class of objects that can be stringified in multiple ways, each of which is useful. The JavaScript standard library deals with this situation by making toString() take an argument, as seen with the Number class.
> 
> Is that the precedent to follow or is having some other way of accessing such string values reasonable too?

IMO both are reasonable. I guess my gut feeling is that adding an option to toString makes sense when this is a very secondary thing that most code won't use (like non-base-10 serializations for numbers). Whereas adding a separate method makes sense when that particular serialization is a first-class domain concept.

I'd also say that if you were to add an option to toString, ideally it'd be a single enum or other parameter, instead of an options bag. If your serialization configuration is complex enough that an options bag has to get involved them probably splitting into separate methods would be better.
Received on Wednesday, 15 March 2017 20:53:28 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 15 March 2017 20:53:28 UTC