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

Re: [WebIDL] toJSON

From: Cameron McCormack <cam@mcc.id.au>
Date: Wed, 06 Jun 2012 11:15:29 +1000
Message-ID: <4FCEAF31.4050602@mcc.id.au>
To: Travis Leithead <travis.leithead@microsoft.com>
CC: Brendan Eich <brendan@mozilla.org>, David Bruant <bruant.d@gmail.com>, "public-script-coord@w3.org" <public-script-coord@w3.org>
Travis Leithead:
> The larger question (in my mind) is whether toJSON extensions should
> get syntactic sugar in WebIDL or not. Since they are so similar (in
> principle) to toString extensions, I'd argue that it would be a good
> idea. Cameron, what do you think?

I think this sounds like a neat idea.  Two things come to mind:

1. Is this just the same as creating a proxy to wrap the object, which
    just forwards everything as-is, calling Object.freeze on that proxy,
    and then using that frozen object as the JSON object?

2. Does it make sense as an API design guideline to, for all objects
    that have a toJSON extension, try to have constructors that can take
    a JSON objects to initialize the object with?  For example:

      [Constructor(IceCreamInit x)]
      interface IceCream {
        attribute DOMString flavour;
        attribute unsigned long scoops;

        void addScoop();
        IceCreamInit toJSON();

      dictionary IceCreamInit {
        DOMString flavour;
        unsigned long scoops;
Received on Wednesday, 6 June 2012 01:16:10 UTC

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