Re: [WebIDL] toJSON

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