I'm a newbie who needs advice about how to use external files of JavaScript
code. I spent an hour this afternoon browsing through JavaScript books at
the local book store. In about 15 different titles, I found a total of about
five pages that covered js files. For all practical purposes, these pages
said, "You can use js files. But we won't tell you how."
Therefore, I hope someone can answer a few questions about js files...
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?
2. Is program flow an issue? That is, does html wait for a JS function to be
called?
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?
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?
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?
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"> ?
Thanks.
Charley
code. I spent an hour this afternoon browsing through JavaScript books at
the local book store. In about 15 different titles, I found a total of about
five pages that covered js files. For all practical purposes, these pages
said, "You can use js files. But we won't tell you how."
Therefore, I hope someone can answer a few questions about js files...
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?
2. Is program flow an issue? That is, does html wait for a JS function to be
called?
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?
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?
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?
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"> ?
Thanks.
Charley
Comment