On 9/2/07, Garrett Smith <[EMAIL PROTECTED]> 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 > [email protected] > https://mail.mozilla.org/listinfo/es4-discuss > _______________________________________________ Es4-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es4-discuss
