Charley Kyd wrote:
[color=blue]
> 1. JavaScript on a web page has un-named routines, and named functions.
> Can we name those un-named routines and put them into a js file? If so,
> are they also defined as functions? Or do we use some other key word to
> define such routines? Can JS functions do everything that the un-named
> routines can do? That is, can we call the un-named routines a function
> even though we don't care what value they return?[/color]
What do you mean by un-named routines? Do you mean code that isn't in a
function? You should really put all stuff in a .js file in functions.
Otherwise AFAIK it will run the code as soon as the .js file is loaded.
[color=blue]
> 2. Is program flow an issue? That is, does html wait for a JS function to
> be called?[/color]
It depends what your programming code does :) If you have a function in the
page that is executed when the user interacts with an element in the page
it will execute the function if it can find it. If the .js file has not yet
loaded then the function won't yet exist so cannot be called and you'll get
an error.
[color=blue]
> 3. Logically, we could have many functions in one js file, or one function
> in each of many js files. Other than ease of programming and use, why
> would I choose one approach rather than the other?[/color]
Probably best to have one file with all the stuff, so only one file has to
be downloaded (it will be cached so further requests in the site won't need
to download it again). If you have separate sections that do different
stuff then you might consider different .js files for the different areas.
[color=blue]
> 4. Within an html page, variables in un-named routines appear to have
> page-level scope. So to define a page-level variable in a js file, do we
> just declare variables at the top of the page outside a routine, as in a
> VB module?[/color]
Declaring variables in the .js file means they have scope for the page.
However, if you try to reference one of those vars before the .js file is
loaded you'll get an error.
[color=blue]
> 5. Do js files stay in memory until the browser is closed? If so, that
> would imply that page-specific code should remain with the page, rather
> than be moved to a js file. Or is there a way to close a specific js
> module when an html page is closed?[/color]
They won't stay in memory. They may remain cached so they don't get
downloaded again. Depends on the browser and cache settings.
[color=blue]
> 6. Can a routine in one js file call a function in another js
> file--assuming that both files are declared with <SCRIPT src="whatever">?[/color]
Yes. As long as they are both loaded.
HTH
Chris
--
Chris Hope
The Electric Toolbox Ltd
http://www.electrictoolbox.com/