So two part question here. Basically, what is the proper practise for javascript function locations? I assumed it would be to have several MyScriptFile.js
files, each with a few functions instead of one huge AllMyScripts.js
file, as not every page needs every function.
However I'm not sure how to reference another function from outside of this file...
My situation: I'm using an AJAX request in many of my pages. Each request response is different (drawn from different files, etc) and is very hard to make dynamic (one-script-fits-all would be difficult). However, I do have my MakeAJAXRequest()
function which creates the request object, which is standard to all DoSomethingWithRequest()
functions.
How do I include MakeAJAXRequest()
in the other files which contain the DoSomethingWithRequest()
functions? It seems as though I should have been able to find this.. but I havn't come across it.
tl;dr I have MakeObject.js
and UseObject.js
. How does UseObject()
reference MakeObject()
?
EDIT: Found that if you include MakeObject
BEFORE UseObject
in your HTML <script>
tags, UseObject
will be able to reference MakeObject
. Seems a little dirty still, as anybody who wants to use the UseObject
script will have to be aware of the MakeObject
dependency...