Subj : Re: Changing Object.prototype.toSource to use double-quotes everywhere To : netscape.public.mozilla.jseng From : Peter Wilson Date : Fri May 13 2005 05:10 pm Brendan Eich wrote: > 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. > Brenden - I'm not sure I see the argument for bloating the core engine with this functionality. It's trivially easy to write a JS function to do this for any arbitrary JS object structure as long as it's legally capable of being represented as a JSON string. Now if you'd like to implement toQuotedPrintable for me......... > Bcc'ing Doug Crockford for his thoughts. > > /be -- Peter Wilson http://www.whitebeam.org http://www.yellowhawk.co.uk ------------------------------------------------------------------------ -- Peter Wilson T: 01707 891840 M: 07796 656566 http://www.yellowhawk.co.uk ------------------------------------------------------------------------ .