function.toString()

D

Dr J R Stockton

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?
 
D

David Mark

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.
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.
 
D

Dr J R Stockton

In comp.lang.javascript message <41fc8017-a659-4d15-86f4-4117973b2f33@d2
1g2000prf.googlegroups.com>, Tue, 11 Dec 2007 02:54:24, David Mark
Yes. I ran into this with some debugging code that inspects functions
and it is quite annoying.


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(){/**/}) .
 
R

Richard Cornford

Dr said:
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.
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.
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]>
, Wed, 12 Dec 2007 18:33:31, Richard Cornford
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.
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.
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
EmeliaBryc

Latest Threads

Top