标签云

微信群

扫码加入我们

WeChat QR Code

This question already has an answer here:

I am writing some javascript files that will not be used with html documents. For example, writing a calculator in js where I'll have different .js files say one for addition, subtraction, multiplication, division, etc..

I'd like to have each math operation in a self contained .js file then have another .js file that will #include the other smaller files and can call the functions from them?

Is that possible?

The math example is just a simple way to try to express what I mean, the real program is a bit more complicated that that and the main purpose of splitting the code up is because It's just easier for me to reason out with small specialized pieces of code.

I do not have any document or dom to work with, just plain .js files with algorithms inside.


You can use webpack with require('otherfile.js');

2018年08月15日25分58秒

it really seems like js is not suitable for my current project. I had to drop javascript and move to another programming language. I though over the intervening time since that original question js would've modernized a bit. Who wants a monolithic file, especially with js async code execution, name collisions, etc... sure i could wrap up functions and make them anon but wow.....

2018年08月16日25分58秒

yes, use require

2018年08月15日25分58秒

I call plagiarism!

2018年08月16日25分58秒