1

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!

1
  • It depends how you're serving your JS. Consider using Browserify. Commented Nov 18, 2015 at 3:41

2 Answers 2

1

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();
}
Sign up to request clarification or add additional context in comments.

Comments

0

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>

1 Comment

ljaz : Thanks! But I want to import class just class A in my HTML page and want the visibility of code of class Bcontained within class A. Also I want to use the class structure of class B in the implementation of class A!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.