How to source another .js from within the .js defined in a script tag?

S

steven.harms

Hi gurus,

1. foo.html has a script tag to reference'foo.js'
2. foo.js wants to use the handy datadumper.js routines
3. How does foo.js become aware of functions in the datadumper.js
namespace?

Is this possible? I'm sure it must be?

Assuming it is....

In JS programming, is there a best practice for building these
'libraries'? Do JS-ers tend to divide the function sets into numerous
external files based on function? By this i mean:

1. greatsite.html uses script tag to reference 'general.js'
2. general.js sources 'ui_widgets.js' and 'transaction.js' and
'word_frobnicate.js', etc.

I'm pretty sure the first half is covered in this a FAQ...but i can't
seem to find it...
 
T

Tom Cole

Hi gurus,

1. foo.html has a script tag to reference'foo.js'
2. foo.js wants to use the handy datadumper.js routines
3. How does foo.js become aware of functions in the datadumper.js
namespace?

Being an interpreted language it doesn't need to know about it until
execution.
Is this possible? I'm sure it must be?

Sure, include a script tag for both foo.js and datadumper.js in your
web resource (HTML, etc.)
Assuming it is....

In JS programming, is there a best practice for building these
'libraries'? Do JS-ers tend to divide the function sets into numerous
external files based on function? By this i mean:

1. greatsite.html uses script tag to reference 'general.js'
2. general.js sources 'ui_widgets.js' and 'transaction.js' and
'word_frobnicate.js', etc.

Typically only if:

1. Each group of code provides very specific and different functions
and
2. The code is getting too large to download quickly.

I've seen code where there is a base package of utility method/objects
and then additional other pieces of code you can include for specific
functions.

You'll see this alot with Google Maps. You've got your script that
includes the base map functions, then there are helper apps out there
like daylight map and Jef Poskanzer's Clusterer script.
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top