I see a lot of articles in Stackoverflow about including one .js file in another, but I'm no wiser after having read them. Some point to requireJS and some to using jQuery, but it seems the jQuery solution is like the chicken and the egg in that I need to include jQuery in order to use it!!
Thus, let's say I want to include sql-debug.js in my own sql reader .js file:
// my_sql.js reader
var sql = require('../sql/sql-debug.js');
//...
My js code is client code in that it is to be loaded by a browser and code dump all of my js code into the same .html file and use . However, I'd like to place it in appropriately named files.
I read a while back that Javascript is the most used language, and yet the designers never thought of a simple way to include another Javascript file!!
If anyone could provide a working solution to the above simple task it would be much appreciated.
UPDATE
Having looked at the cited answers I still don't get it. Let's say I have the following files all in the same directory: test.html [main html], test_loading.js [copy&paste of code from cited sources] and apple.js [a simple js class] as follows:
test.html
<!DOCTYPE html>
<html>
<head>
<title>Basic skeleton</title>
<script type="text/javascript" src="jquery-1.9.0.js"></script>
<script type="text/javascript" src="test_loading.js"></script>
<style>
body{
/* set margin to 0 and overflow to hidden, to
use the complete page */
margin: 0;
overflow: hidden;
}
</style>
</head>
<body>
<!-- Div which will hold the Output -->
<div id="WebGL-output">
</div>
<!-- Javascript code that runs our Three.js examples -->
<script type="text/javascript">
// once everything is loaded, we run our Three.js stuff.
$(function () {
// here we'll put the Three.js stuff
});
</script>
</body>
</html>
test_loading.js
$.getScript("apple.js", function(){
alert("Script loaded but not necessarily executed.");
});
apple.js
class Apple {
}
Tell me why this doesn't work.