I am a newbie in developing JavaScript libraries. I've a basic doubt on how to include a js file into another js file that is dependent on the former. For example, I'm building a javascript library that replicates the class structures present in the Server code.There are cases for example, where class B is contained in class A. I want to make a seperate js file to denote class B and then include this in the definition of class A. How do I go about this ?
I appreciate your help.
Thanks!
-
It depends how you're serving your JS. Consider using Browserify.SLaks– SLaks2015年11月18日 03:41:09 +00:00Commented Nov 18, 2015 at 3:41
2 Answers 2
You can define a function in b.js which returns B class (function) and call it inside class A
b.js
getClassB function (){
//define your B class here and return it at the end
return B;
}
a.js
class/function A(){
var B = getClassB();
}
Comments
If you are using it in html page, simply import class A file first and then class B file like
<script src="path_to_class_a_file"></script>
<script src="path_to_class_b_file"></script>