eval

R

Richard Cornford

Let us hear :)

I imagine that Randy is in part alluding to the thread from
17th August 2003 with the subject "Alternative to eval",
which, because the application was for an Intranet, did not
find a better alternative.

Another possibility where eval seems to be required is the full
emulation of Function.prototype.apply for IE 4 and 5.0 (which
don't implement it):-

<URL:
http://groups.google.com/[email protected]
A full emulation of function.prototype.apply may be required
if the curry function being discussed earlier this week was to
be used with the older IE/JScript versions.

Richard.
 
D

Douglas Crockford

Another possibility where eval seems to be required is the full
emulation of Function.prototype.apply for IE 4 and 5.0 (which
don't implement it):-

Function.prototype.apply = function (o, a) {
var r, x = '____apply';
o[x] = this;
switch ((a && a.length) || 0) {
case 0:
r = o[x]();
break;
case 1:
r = o[x](a[0]);
break;
case 2:
r = o[x](a[0], a[1]);
break;
case 3:
r = o[x](a[0], a[1], a[2]);
break;
case 4:
r = o[x](a[0], a[1], a[2], a[3]);
break;
case 5:
r = o[x](a[0], a[1], a[2], a[3], a[4]);
break;
case 6:
r = o[x](a[0], a[1], a[2], a[3], a[4], a[5]);
break;
default:
alarm('Time to add another case to apply.');
}
delete o[x];
return r;
};

The only thing I use eval for is converting JSON strings to objects.

http://www.JSON.org
 
R

Richard Cornford

default:
alarm('Time to add another case to apply.');
}
delete o[x];
return r;
};

Which is why I specifically said "full emulation". I freely admit (and
explained in the post I referenced) that in all "real world"
applications of apply a partial emulation, that does not require eval,
would be sufficient.

I mentioned the apply emulation in relation to the curry function(s)
from "Creating true copies (of objects) in JS (possible?)" because, if
that function is to be written to accept a theoretically unlimited
number of parameters it will need a full emulation of apply. On the
other hand, if it is accepted that in actual applications of that type
of function there will be a known upper limit to the number of
parameters needed, then the curry function does not need to use apply at
all.

Richard.
 
T

Thomas 'PointedEars' Lahn

Albert said:
Yes, you did. You should get informed when Cancel works and when it
doesn't.

Hm, either your news server does not obey Cancel (which is alas not yet
backed up by RFCs) or it could be a bug in Mozilla/5.0 rv:1.5 MailNews.
Unfortunately, I don't have access to control.cancel on my news server.

Could you please post the message ID of the dupe, so I can check that?


PointedEars
 
T

Thomas 'PointedEars' Lahn

Thomas said:
Hm, either your news server does not obey Cancel (which is alas not yet
backed up by RFCs) or it could be a bug in Mozilla/5.0 rv:1.5 MailNews.
Unfortunately, I don't have access to control.cancel on my news server.

Could you please post the message ID of the dupe, so I can check that?

Not necessary. I've downloaded messages from another news server with
another newsreader and there was only one posting from me in this thread.
The Cancel worked and Mozilla is not buggy on that. If you see dupes either
your news server did not (yet) obey it or your newsreader does not provide
appropriate feedback.


HTH

PointedEars
 
L

Lasse Reichstein Nielsen

The first one, John Stocktons site has a textarea for input of
script to test it. When testing it, it seems to be the best way to
do it (using eval).

The other one was a problem I had a while back (it was discussed
here) where I had a select list that had fractions as its value.

I remember that :)
The fractions were random in the sense that they weren't always the
same denominator. The problem was trying to convert the fraction to
a decimal. It turned out that, in some browsers, eval performed at
the same level as splitting on the / and then dividing.

If it was only at the same level, then I wouldn't use eval. You need
total control of the arguments to eval (or a syntax check), which should
outweigh the advantage you get from shorter code.

As for speed. As far as I can see, eval is *much* slower (more tha 5x)
than using split in IE 6. A little faster yet is finding the "/" with
indexOf and using substring to get the parts:
var i = str.indexOf("/");
return str.substr(0,i)/str.substr(i+1);

In Opera 7.2, split was fastest and eval slowest. In MozFB, split and
eval are comparable. In Netscape 4.8, eval is actually twice as fast
as split, and 1.5 times as fast as using substring. It is generally
slower than the other browsers, though.
Where's the one place you use it?

A text area for input of scripts (actually the one that I link to in
this signature).

/L
 
T

Thomas 'PointedEars' Lahn

HikksNotAtHome said:
[...] Thomas 'PointedEars' Lahn said:
Not necessary. I've downloaded messages from another news server with
another newsreader and there was only one posting from me in this thread.
The Cancel worked and Mozilla is not buggy on that. If you see dupes either
your news server did not (yet) obey it or your newsreader does not provide
appropriate feedback.

Go to groups.google.com and look at the archive. http://tinyurl.com/tw51 and it
does indeed show the duplicate posts. Message 38 and 39 in the eval thread.

One should practice what they preach.

It is widely known that Google Groups does not obey Cancel messages
(but I will remove it manually there, now that it has been archived),
and it seems the same goes for http://tinyurl.com/tw51 and other web
archives. You may try other *news* *servers*, like news.cis.dfn.de or
news.tu-ilmenau.de (I tested the latter) to see this confirmed.


HTH

PointedEars

P.S.
I would not have answered your posting if I had Internet connection
at home by now.
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
That is the use of it that I was referring to with John's site. Didn't know
yours had it as well (I very seldom follow signature URLs).

Elsewhere on the site one can find instances of a somewhat different
usage.

Sometimes, where an input number is required, a user may wish to supply
an expression; for example, if a distance in kilometres is required, it
may be convenient to supply "<miles>*1.609. I would only do this on a
technical page, such as astro.htm; it would not be appropriate for
others.
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top