Subj : Re: Function.toString - Silly Idea To : netscape.public.mozilla.jseng From : Martin Honnen Date : Fri Aug 05 2005 08:09 pm Baconbutty wrote: > A further idea I has was this. If I call toString() on a function > reference in the JScript engine, it will include all of the comments > originally contained within the JS code, including /* */ comments. > I could then access this using:- > > myDataStore.toString() > > and extract the test using RegExp or other like methods. > > However, unlike the JScript engine, I have found that the Mozilla > engine strips out comments in toString(). As far as I remember from previous discussions on this Mozilla's JavaScript engine compiles a function to byte code (which is not likely to store anything not executable like comments) and decompiles the byte code stored for a function when you call toString. As for your idea, the ECMAScript edition 3 specification says on the toString method of Function objects: "An implementation-dependent representation of the function is returned. This representation has the syntax of a FunctionDeclaration. Note in particular that the use and placement of white space, line terminators, and semicolons within the representation string is implementation-dependent." So you can try to use your approach if you want but you have to be aware that the result is implementation dependent and you can't complain if some implementation does not give you the same result as another implementation. I think if you want to store and load data then you need to look at host specific ways to do that, e.g. in the browser by now you can use XMLHttpRequest in Mozilla, Opera 8, Safari 1.2, Konqueror 3.3, IE 5 and later to load XML data from a URL. -- Martin Honnen http://JavaScript.FAQTs.com/ .