I am new to Java script. I couldn't figure out how to make multiple JS files to be able to call each other's functions or use each other's classes.
Here is the structure of my small project:
- ./index.hml
- ./css/style.css
- ./script/library.js
- ./script/main.js
- ./script/demo.js
All my logic is in library.js. It has a class called "Transaction" and another one called "Settler". All my business logic is in this file.
The demo.js is supposed to create some random data and then create Transaction objects in an array, and then send to Settler object.
I cannot make the demo.js to see the library.js. Can anyone help.
Here is what I want to do in demo.js:
demo(){
1. for-loop: create one random "Transaction" and add it to a map
2. create a Settler object and send my Transaction-map object to the object as a contructor argument
}
main.js is for the index.html. So this one is supposed to use the demo.js only. The "main.js" has the dom manipulation. So "main.js" would use "demo.js" to get some randomized data and manipulate it on the index.html.
I tried my luck with "require" etc, but I couldn't make it work..
How can I have a separate js file and use the class definitions and methods in that file from my own js code?
Thanks
Note: I use Visual Studio Code and run my code initially on nodejs.