starting again! why fails?

G

Geoff Cox

Rob,

Out of interest using Firefox the code below takes 33 seconds (as
against the 13 seconds when using IE) before the first image is
available.

Cheers

Geoff

var picture = new Array();
var ig = 0;
var ig_max = 7;

function preload_imgs()
{
if(ig < ig_max)
{
picture[ig] = new Image();
picture[ig].onload = preload_imgs;
picture[ig].src = "pic" + ig + ".jpg";
ig++;
}
}

preload_imgs();
 
G

Geoff Cox

which is frustrating as the explanation was a comprehensive one.

Come off it Zoe! THis explanation was hidden by jargon! Just look at
Rob's explanation - that I could understand. Cann't you see the
difference?!

Geoff
 
G

Geoff Cox

The assigning of the src attribute for the first picture comes after
calling the function again - at least it appears so above. I would
have thought the order would be

picture[ig] = new Image();
picture[ig].src = "pic" + ig + ".jpg"
picture[ig].onload = preload_imgs;

What am I mssing here?

it makes no difference, the onload is set for when the image loads and as
you know this takes a few seconds. so the image will be loading and will
call the function AFTER it has completed that task, in the meantime the rest
of the code is free to execute...is set the source ect.

OK thanks Zoe

Cheers

Geoff
 
G

Geoff Cox

Yes but you haven't said what the difference is between

picture[ig].onload = preload_imgs;

and
picture[ig].onload = preload_imgs();

to be fair that is not the question that I answered because you had not
asked it !!!

Zoe,

I did ask it but I guess it was in a different message! Sorry.

OK - so what is the difference?!

Cheers

Geoff
 
R

Robi

Geoff Cox wrote in message news:[email protected]...
Yes but you haven't said what the difference is between

picture[ig].onload = preload_imgs;

and

picture[ig].onload = preload_imgs();

to be fair that is not the question that I answered because you had not
asked it !!!

Zoe,

I did ask it but I guess it was in a different message! Sorry.

OK - so what is the difference?!

I would suggest reading, re-reading and analyzing the following message:

it is explained pretty well by RobG I would say.
Both, RobG and Stephen Chalmers give their thoughts about it
explaining the difference.

oh, or http://tinyurl.com/clp9j and read the other two messages following it :)

HTH
 
W

web.dev

Geoff said:
picture[ig].onload = preload_imgs;

I have said what this code does !!!

it create a call to the preload_imgs function when the currently loaded
image loads.

Zoe,

Yes but you haven't said what the difference is between

picture[ig].onload = preload_imgs;

and
picture[ig].onload = preload_imgs();

Cheers

Geoff

Geoff,

The difference is the following:

1. picture[ig].onload = preload_imgs;
This statement assigns the function to the onload event.

2. picture[ig].onload = preload_imgs();
This statement assigns the return value of the function call to the
onload event.
 
R

Robi

Robi wrote in message news:[email protected]...
Geoff Cox wrote in message news:[email protected]...
Yes but you haven't said what the difference is between

picture[ig].onload = preload_imgs;

and

picture[ig].onload = preload_imgs();

to be fair that is not the question that I answered because you had not
asked it !!!

Zoe,

I did ask it but I guess it was in a different message! Sorry.

OK - so what is the difference?!

I would suggest reading, re-reading and analyzing the following message:
news:[email protected]

oops!!!

or
http://groups.google.com/group/comp.lang.javascript/msg/fc14707df441116b

Sorry, Richard Cornford explains it...

mea maxima culpa
 
G

Geoff Cox

The difference is the following:

1. picture[ig].onload = preload_imgs;
This statement assigns the function to the onload event.

2. picture[ig].onload = preload_imgs();
This statement assigns the return value of the function call to the
onload event.

Got it ! Thanks web dev and my thanks to all others involved

Geoff
 
R

Richard Cornford

Geoff said:
Come off it Zoe! THis explanation was hidden by jargon!

That "jargon" being:-

assigns and assigned
called and call
reference and referred
function and function object
property
value
object
array element
return value

-?

The problem with your describing my explanation as being "hidden" by
this "jargon" is that the terms used are probably the simples, and
certainly the most appropriate, terms for the concepts that they
describe. And they describe concepts that are fundamental to javascript.
Just look at Rob's explanation - that I could
understand. Cann't you see the difference?!

RobG's final contribution to this thread is dated Mon, 19 Sep 2005
02:37:05 GMT, and you re-asked for an explanation of the code I
explained at Mon, 19 Sep 2005 09:24:10 GMT, about 7 hours later, which
suggests that his explanation of this code was not any more informative
than mine was. Of course RogG did not explain this code so your drawing
a comparison is somewhat strange. You will also find that if he
explained that code he would use very similar terminology to that I
used.

And the explanation that you received from web dev is incomplete in a
way that could result in misconceptions if taken in isolation (and still
uses a significant proportion of the "jargon" terminology that I used).

Richard.
 
R

Richard Cornford

Geoff said:
Richard,

You have certainly failed to clarify the postion for me - but
then I suspect that you were just trying to make a point!

No, I was trying to make a point, but my explanation was correct, and
about as complete as it could be without getting into the specified
algorithms for the operations.
I have a background in science education and I always remember
the words of Sir Lawrence Bragg that a really good scientist
can make even the most complex theory comprehensible. Just a
matter of how you go about it.

There is a difference between an explanation that can be comprehended
and an explanation that anyone can comprehend. Would Sir Lawrence Bragg
have been able to compose an explanation of General Relativity such that
my 4 year old niece would understand it, or even perceive it as
something other than a rather dull fairly tail?

Science, like most other subjects, requires a certain grounding, and the
acquisition of a vocabulary, if it is gong to be talked about at all.

Richard.
 
G

Geoff Cox

Richard,

I'm sorry if I went a little OTT. No doubt your description was
concise and correct.

All I was trying to say was that I found Rob's longer account easy to
follow.

I do agree I need to make the effort to understand more of how
Javascript works, so thanks for your comments.

Cheers

Geoff
 

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
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top