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

Re: [WebIDL] toJSON

From: Simon Pieters <simonp@opera.com>
Date: Thu, 31 May 2012 10:45:45 +0200
To: "David Bruant" <bruant.d@gmail.com>
Cc: "public-script-coord@w3.org" <public-script-coord@w3.org>
Message-ID: <op.we5zyjzwidj3kv@simons-macbook-pro.local>
On Thu, 31 May 2012 10:26:02 +0200, David Bruant <bruant.d@gmail.com>  

> 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. 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. 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  

> Adding a toJSON seems to be less intrusive.
> David

Simon Pieters
Opera Software
Received on Thursday, 31 May 2012 08:45:40 UTC

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