[Javascript] How to call scripts that are all in one file...?

Jonathan Gold johnnyclock at gmail.com
Sat Feb 4 04:39:49 CST 2006


OK! Thanks to all. Gosh, I had a lot of trouble with this, but I think
it was due to tiny errors that kept creeping into my code as I turned
non-function routines into functions. Finally got all six scripts into
one .js file and correctly linked to it and correctly called the (now)
six functions. It earned me another green light at the
http://www.websiteoptimization.com/services/analyze/
free Web Page Speed Report. Check it out, if you don't know it, and
tell me what you think of it's recommendations.

Again, thanks very much to all.

Best regards,

Jonathan

On 2/3/06, Paul Novitski <paul at novitskisoftware.com> wrote:
> At 06:43 PM 2/3/2006, Rick Holcomb wrote:
> >You could wrap each file in a function and then call the function when
> >needed.
> ...
> >Function routine1{
> >         //Insert all code from the myroutine1.js file
> >}
> ...
> ><script type="text/javascript">
> >         routine1;
> ></script>
> ...
>
> Oops: wrong answer.  To call/execute/run a function, you have to
> include the open & close parens after the function name:
>
>          Function routine1{
>                  //Insert all code from the myroutine1.js file
>          }
>          ...
>          <script type="text/javascript">
>                  routine1();
>          </script>
>
> Invoking the name of the function without the parentheses recalls the
> text of the function but doesn't execute that script.  For example,
> to cause a function to run when the page loads you can write:
>          window.onload = routine1;
> i.e., set the function window.onload() equal to the script of
> function routine1().  When the page finishes loading, the browser
> will execute window.onload().
>
> To display the text of a function, write:
>
>          alert(routine1);
>
> To run a function and display its return value, write:
>
>          alert(routine1());
>
> For more on functions see:
> http://www.croczilla.com/~alex/reference/javascript_guide/fcns.html
>
>
> Here are two great fundamental references:
>
> Core JavaScript Guide
> http://www.croczilla.com/~alex/reference/javascript_guide/
> [the JavaScript language itself]
>
> Gecko DOM Reference
> http://developer.mozilla.org/en/docs/Gecko_DOM_Reference
> [how JavaScript works with the Document Object Model (DOM) of an HTML page]
>
>
> Regards,
> Paul
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>


--
Jonathan
Berkeley, CA
http://home.pacbell.net/jonnygee/


More information about the Javascript mailing list