Re: This (Javascript) function has an onClick event that calls a function that calls This function



In message <453dcb16$0$338$e4fe514c@xxxxxxxxxxxxxx>, Tue, 24 Oct 2006
10:13:07, Maarten Wiltink <maarten@xxxxxxxxxxxxxxxxxx> writes
"Bob Richardson" <bobr at whidbey dot com> wrote in message
news:uaGdndFAAeR1GaDYnZ2dnUVZ_vWdnZ2d@xxxxxxxxxxxxxxxxx
[...]
I'm sure you see the problem...prevmon(), in the onClick event, is
not defined prior to being mentioned in the onClick event. But what's
the solution?

The solution is that there is no problem. Javascript is an interpreted
language with very lazy semantics. Functions are not resolved ahead of
time, but only when they're actually called. At that time, the entire
source is scanned, so forward declarations aren't necessary.

I agree with the second half of your last sentence, but not with the
first half (that would be intolerably slow).

In the simple case of

function A() { B() }
function B() { A() }

A()

the names and addresses of the functions will be put in a list during a
pre-execution scan; during execution, it is only necessary to seek
within the list (which can be done more or less efficiently).
News:comp.lang.javascript would phrase that better.

It's a good idea to read news:comp.lang.javascript and its FAQ. See sig.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
.