Bart said:
I see how it can be done when the number of seconds is harcoded. But
that was what I wanted to avoid (see previous), by working with a
configuration var in the beginning.
As my code shows, it can be done without `t' being global *and* (what my
code doesn't show explicitly yet) without the number of seconds being
hardcoded. Watch for the Object initializer.
That is certainly so... but how is this relevant here ?
The OP should not be presented with ill-advised code.
var f = new Array();
f[0] = new Image();
Untested construction of host object.
But these tests are not necessary at all.
The test of `Image' being [[Construct]]able is certainly necessary.
However, only its [[Call]]ability can be determined with probability
*and* compatibility.
Let's see. Can you name a reasonable browser where 'var a = new Image
();' fails ?
I can't.
That does not mean anything.
But I only wanted to backup my statement that Image and Array have
been supported since javascript 1.1. That information is not outdated
at all.
Yes, it is, regarding `Image' (will you please drop `Array' now? I have
never said that it needed to be feature-tested anymore!). When a feature,
(here: Image) is not part of a programming language (here: JavaScript) since
more than a century, documentation that claims its availability is obsolete
regarding a discussion that is based on current versions of said programming
language.
[ snip code ]
if (t >= f.length) t=0;
Inefficient operation; as you initialize with 0, and increment by 1,
only `>' is needed.
Nope. Try to run the code with '>' in stead of '>='. It errors out at
the point where both values are equal. You could use '=='.
if (t > f.length - 1)
works fine.
Can't you see how absurd your comment is ??
No. I proposed using `>' instead of `>='.
I proposed
if (t == f.length)
and you want
if (t > f.length - 1)
Your new proposition is arguably more efficient than your previous one,
but neither as safe, nor safer or more efficient than mine.
However, I would not use a global variable here:
function refr(img, intv, t)
{
[...]
me.target.src = (typeof f[t].src != "undefined" ? f[t].src : f[t]);
There is the precaution so that this works even if `Image' is unsupported..
In which cases is the Image-object unsupported ?
See above.
Absolutely, but not Ex Absurdum. Your check 'if (typeof document ==
"undefined") {...' is absurdism in its most pure form.
How so? `document' is either a property of a host object in the scope
chain, or a host-defined property of the Global Object since more than a
century; its availability depends on the host environment, and not on the
language version.
That is a totally other thing.
It isn't. You said, in essence, that the code was hard to read; I pointed
out that, ignoring the subjectiveness of "hard", that code wouldn't be hard
to read if it was generalized as described. Whether or not the location of
the generalized code would be within a library or not does not even matter
for this. However, it stands to reason that feature-testing is that common
a task, and the approach likely subject to changes, that it should not be
simply copy-pasted as is; one or more external script resources, commonly
called script library/libraries, can provide that.
I am not surprised. You would rather continue writing error-prone code in
order to avoid feature-testing code that you do not understand, yes?
but let's not move into that, please.
You started it, you have to live with it.
Aha. You have a magic hat to make code disappear.
No, the code would not disappear completely. However, it disappears from
the user code.
Which are two corrections.
Quibbling over words. I corrected myself only once.
https://developer.mozilla.org/en/window.setTimeout is not irrelevant
when you want to learn about setTimeout(). It should be your first
place to look.
You will observe that this article is located correctly under "Gecko DOM
Reference" and not "JavaScript Reference". The canonical URI is
<
https://developer.mozilla.org/en/DOM/window.setTimeout>.
However, its Compatibility section is misleading regarding its JavaScript
version information, and wrong regarding its MSHTML version information.
That is unsurprising as MDC is a Wiki, and few people know how to
differentiate between the programming languages, and the APIs (like DOMs)
that can be used with them. I shall endeavour to correct the article in due
course.
PointedEars