Subj : Re: Changing Object.prototype.toSource to use double-quotes everywhere To : zwetan From : Brendan Eich Date : Thu May 12 2005 03:52 pm zwetan wrote: > hello, > >>Just switching things so >> >>var o = {foo: "bar", '$#@%': 42}; >>o.toSource() >> >>results in a string containing {foo:"bar", "$#@%":42} instead of >>{foo:"bar", '$#@%':42} is a small change that should be easy to adapt >>to, if any existing consumers of toSource output have come to depend on >>single quotes being used, if any quoting is used, around property ids. >> >>Comments? >> > > > would it not be more simpler to let users "override" the prototype method > at runtime with their own method instead of changing the code-base ? Yes, it would be simpler for me. No, it would not be simpler for people trying to produce JSON-compatible strings, because overriding toSource is non-trivial. I'm all in favor of simplifying things for me, though. And the more I think about it, since JS doesn't quote all property identifiers, we are not JSON-compatible even if we double- rather than single-quote. So now I am wondering whether the better answer is not to output JSON via a new option to toSource, or via a toJSONString method. JSON doesn't also handle cycles and join points, so if a JS object graph that's not a tree is toSource'ed or toJSONString'ed, and the consumer wants JSON, it will choke on the sharp variables. Bcc'ing Doug Crockford for his thoughts. /be .