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

Re: [WebIDL] toJSON

From: David Bruant <bruant.d@gmail.com>
Date: Thu, 31 May 2012 10:53:13 +0200
Message-ID: <4FC73179.3000205@gmail.com>
To: Simon Pieters <simonp@opera.com>
CC: "public-script-coord@w3.org" <public-script-coord@w3.org>
Le 31/05/2012 10:45, Simon Pieters a écrit :
> On Thu, 31 May 2012 10:26:02 +0200, David Bruant <bruant.d@gmail.com> 
> wrote:
>> Le 31/05/2012 09:47, Simon Pieters a écrit :
>>> On Wed, 30 May 2012 19:30:43 +0200, David Bruant 
>>> <bruant.d@gmail.com> wrote:
>>>> Hi,
>>>> My reading of the current state of the spec is that
>>>> JSON.stringify(anyEvent) is '{}' which is close to useless.
>>> Why can't we change JSON.stringify() to make it not useless instead 
>>> of sprinkling toJSON on everything?
>> JSON.stringify is part of ECMAScript 5 is widely deployed and used 
>> all over the place. I'm not against the idea of changing it upfront, 
>> but how do you do that without introducing backward-compat issue?
> The back-compat would be the same, more or less.
 From an absolute point of view, adding toJSON would be also a backward 
incompatibility. However, due to the uselessness you noted above, I'm 
convince people are not using JSON.stringify on DOM objects. So it's 
likely that this will not introduce backward compatibility issues.

> JSON.stringify already makes use of "toJSON" properties on objects, so 
> adding toJSON everywhere makes everything "work" in JSON.stringify as 
> well. ES5 already has Date.toJSON for this purpose.
> I wasn't aware about that when I wrote the previous email.
To be honest, I started this thread specifically because i learned about 
toJSON yesterday and thought it could be beneficial for the DOM.

> With that in mind, it makes more sense to sprinkle toJSON everywhere, 
> at least if we expect different things to have different rules for 
> toJSON (like with Date).
Indeed, WebIDL feels like the proper place to do this change. I'm glad 
we agree :-)

Received on Thursday, 31 May 2012 08:53:49 UTC

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