JSON Methods?

Garrett Smith dhtmlkitchen at gmail.com
Sat Sep 1 18:25:56 PDT 2007


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.

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.



More information about the Es4-discuss mailing list