Connecting Tech Pros Worldwide Help | Site Map

function.toString()

 
LinkBack Thread Tools Search this Thread
  #1  
Old December 10th, 2007, 10:45 PM
Dr J R Stockton
Guest
 
Posts: n/a
Default function.toString()

Take a general user-defined function F.

In IE4 & 6 (& IIRC 7), F.toString() gives the function as written, with
the original comment and whitespace.

In FireFox 2 and Opera 9, F.toString() apparently regenerates the
function from a quasi-tokenised form, both losing comment and inserting
new whitespace; the whitespacing is similar but not the same.

Are there any other systems in which the behaviour of F.toString() is
significantly different from both the IE type and the FF/O type? If so,
which, and what do they do?

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.merlyn.demon.co.uk/clpb-faq.txt RAH Prins : c.l.p.b mFAQ;
<URL:ftp://garbo.uwasa.fi/pc/link/tsfaqp.zipTimo Salmi's Turbo Pascal FAQ.

  #2  
Old December 11th, 2007, 09:55 AM
David Mark
Guest
 
Posts: n/a
Default Re: function.toString()

On Dec 10, 5:42 pm, Dr J R Stockton <j...@merlyn.demon.co.ukwrote:
Quote:
Take a general user-defined function F.
>
In IE4 & 6 (& IIRC 7), F.toString() gives the function as written, with
the original comment and whitespace.
>
In FireFox 2 and Opera 9, F.toString() apparently regenerates the
function from a quasi-tokenised form, both losing comment and inserting
new whitespace; the whitespacing is similar but not the same.
Yes. I ran into this with some debugging code that inspects functions
and it is quite annoying.
Quote:
>
Are there any other systems in which the behaviour of F.toString() is
significantly different from both the IE type and the FF/O type? If so,
which, and what do they do?
I haven't ran into any. Like most things, this seems to be IE vs.
everything else. In this rare case, I prefer IE's implementation.
  #3  
Old December 11th, 2007, 10:45 PM
Dr J R Stockton
Guest
 
Posts: n/a
Default Re: function.toString()

In comp.lang.javascript message <41fc8017-a659-4d15-86f4-4117973b2f33@d2
1g2000prf.googlegroups.com>, Tue, 11 Dec 2007 02:54:24, David Mark
<dmark.cinsoft@gmail.composted:
Quote:
>On Dec 10, 5:42 pm, Dr J R Stockton <j...@merlyn.demon.co.ukwrote:
Quote:
>Take a general user-defined function F.
>>
>In IE4 & 6 (& IIRC 7), F.toString() gives the function as written, with
>the original comment and whitespace.
>>
>In FireFox 2 and Opera 9, F.toString() apparently regenerates the
>function from a quasi-tokenised form, both losing comment and inserting
>new whitespace; the whitespacing is similar but not the same.
>
>Yes. I ran into this with some debugging code that inspects functions
>and it is quite annoying.
>
Quote:
>>
>Are there any other systems in which the behaviour of F.toString() is
>significantly different from both the IE type and the FF/O type? If so,
>which, and what do they do?
>
>I haven't ran into any. Like most things, this seems to be IE vs.
>everything else. In this rare case, I prefer IE's implementation.

So do I, as you will no doubt have realised if you have looked at my
site. OTOH, ISTM that it would be good if function.toString() took
an optional Boolean argument LayItOutAgain with parameter absent
maybe meaning "as previous call".

I'll keep using !/\*/.test(function(){/**/}) .

--
(c) John Stockton, Surrey, UK. replyYYWW merlyn demon co uk Turnpike 6.05.
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html-Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm: about usage of News.
No Encoding. Quotes precede replies. Snip well. Write clearly. Mail no News.
  #4  
Old December 12th, 2007, 05:35 PM
Richard Cornford
Guest
 
Posts: n/a
Default Re: function.toString()

Dr J R Stockton wrote:
Quote:
Take a general user-defined function F.
>
In IE4 & 6 (& IIRC 7), F.toString() gives the function as
written, with the original comment and whitespace.
>
In FireFox 2 and Opera 9, F.toString() apparently regenerates
the function from a quasi-tokenised form, both losing comment
and inserting new whitespace; the whitespacing is similar but
not the same.
And (in the aspects stated) both fully comply with the specification,
which explicitly states that white space in the representation of the
function is implementation dependant.
Quote:
Are there any other systems in which the behaviour of F.toString()
is significantly different from both the IE type and the FF/O
type? If so, which, and what do they do?
In all Opera versions before 7, if a string included a regular
expression literal that literal would be represented in the function's -
toString - output as "[object]". That was (arguably, but probably) a
bug, but it does illustrate the problems with assuming too much from of
the - toString - method of functions, and one of the dangers in trying
to take a function's - toString - output and - eval - it back into a
function object.

Richard.

  #5  
Old December 12th, 2007, 10:45 PM
Dr J R Stockton
Guest
 
Posts: n/a
Default Re: function.toString()

In comp.lang.javascript message <fjp9hl$sku$1$830fa7a5@news.demon.co.uk>
, Wed, 12 Dec 2007 18:33:31, Richard Cornford
<Richard@litotes.demon.co.ukposted:
Quote:
>Dr J R Stockton wrote:
Quote:
>Take a general user-defined function F.
>>
>In IE4 & 6 (& IIRC 7), F.toString() gives the function as
>written, with the original comment and whitespace.
>>
>In FireFox 2 and Opera 9, F.toString() apparently regenerates
>the function from a quasi-tokenised form, both losing comment
>and inserting new whitespace; the whitespacing is similar but
>not the same.
>
>And (in the aspects stated) both fully comply with the specification,
>which explicitly states that white space in the representation of the
>function is implementation dependant.
.... -dependent, to be exact. It says more than that explicitly; but it
leaves the combining of string literals implicitly allowed. I was aware
of 16262 15.3.4.2.
Quote:
Quote:
>Are there any other systems in which the behaviour of F.toString()
>is significantly different from both the IE type and the FF/O
>type? If so, which, and what do they do?
>
>In all Opera versions before 7, if a string included a regular
>expression literal that literal would be represented in the function's
>- toString - output as "[object]".
I can live with that. There can't be many users of Opera<7 left.
Quote:
That was (arguably, but probably) a bug, but it does illustrate the
>problems with assuming too much from of the - toString - method of
>functions, and one of the dangers in trying to take a function's -
>toString - output and - eval - it back into a function object.
I've no (present) intention of doing that. Thanks.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk DOS 3.3, 6.20 ; WinXP.
Web <URL:http://www.merlyn.demon.co.uk/- FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <URL:http://www.merlyn.demon.co.uk/batfiles.htm- also batprogs.htm.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.