[thelist] Proper Way of Separating 'Library' Files in JS

Andrew Clover and-evolt at doxdesk.com
Fri Jun 17 09:49:35 CDT 2005

Matt Warden <mwarden at gmail.com> wrote:

 > Currently, I am doing this:

 > <script type="text/javascript" src="js/lib/hashtable.js"></script>
 > <script type="text/javascript" src="js/lib/mylibrary.js"></script>

Yeah, that's the way it's usually done. There is no facility in 
JavaScript to import from other JavaScript.

Workarounds include fiddling with DOM manipulation/innerHTML to add 
extra <script> elements to the page, and using XMLHttpRequest to fetch 
and eval()uate external scripts. However neither method is reliable 
cross-browser so for simple scripts you are better off with what you have.

(OT: I'm not sure what you want a hashtable for, isn't JS's built-in 
Object good enough?)

Andrew Clover
mailto:and at doxdesk.com

More information about the thelist mailing list