There are several ways to call functions in another file.
1) Native Solution
In your HTML file, make sure your <script>
tag importing sdk.js
is loaded first, like so
<script src="./sdk.js/"></script>
<script src="./a.js/"></script>
<script src="./b.js/"></script>
As long as sdk.js
declares the function in the global namespace, any file loaded afterwords should have access to it
2) ES6
If you can use ES6 features (via babel or webpack, for example), then your other scripts can import
the file. Take the following example:
sdk.js:
export var foo = function(){
return "foo";
}
a.js
import foo from "./sdk.js";
foo();
3) Node.js way
Node.js supports require
, another way of importing files. These files would operate under their own scope, and you would have to use module exports to make a function or variable "public".
** Worth nothing that this only works in node, not the browser, however
4) Require.js way
You can use the require.js library to import other files as well.
Additional Resources
This SO Question has far more in-depth answers than what I've outlined above. Best of luck!