JSON Methods?

Lars T Hansen lth at acm.org
Mon Sep 3 02:09:39 PDT 2007


On 9/2/07, Garrett Smith <dhtmlkitchen at gmail.com> wrote:
> I was wondering about the new JSON methods:
>
> Object.prototype.toJSONString
> String.prototype.parseJSON
>
> to me, parseJSON seems like it should not be a String prototype method.
>
> I'm thinking about other "parse" type of methods, like Date.parse( s );
>
> Here, it's fairly obvious what parse should return -- A Date.

Date.parse() returns a number, not a Date.  E262-3 15.9.4.2 first paragraph.

--lars

> A parse method always parses a string, and in any well-designed API,
> returns an object of the class it's bound to. We've already seen this
> with Date.parse(), in other languages, like Java, there are
> Integer.parseInt, Double.parseDouble.
>
> It seems to me to make more sense to put parseJSON on object, but then
> since JSON is a subset of Object, why not just put it as a subclass of
> Object?
>
> Object +
>             |
>             JSON
>
> It seems to me, that Object.prototype.toJSONString could be also
> implemented on a JSON instance.
>
> JSON
>
> constructor:
> JSON( object )
> static JSON parse( s ) throws SyntaxError
> JSON.prototype.toString( )
> JSON.prototype.isValid( )
>
>
> Garrett
>
> --
> Programming is a collaborative art.
> _______________________________________________
> Es4-discuss mailing list
> Es4-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es4-discuss
>



More information about the Es4-discuss mailing list