Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1241
  • Last Modified:

How import another module into .js script

I create a program i javascript - not in  web page, but for running from script .js file. The problem is - i have some functions in another .js file, and I want to call them from my script ..So, I need any way, how to import, on include, or show to way to another file, where these  functions are defined.


Something like this :
file1.js :
function MyFun()
{.........}

file2.js :
MyFun() // I' like to call MyFun

But I can't find any command in javascript to do it....

Thanks for any reply...
0
petrph
Asked:
petrph
1 Solution
 
Michel PlungjanIT ExpertCommented:
file2:
document.write('<script src="file1.js"><\/script>')
MyFun();
0
 
petrphAuthor Commented:
Thank, but this is , what I can't use - not in  web page -so no document.write. Simple running .js file.
0
 
DauheeCommented:
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Michel PlungjanIT ExpertCommented:
What do you mean "Not in a web page"?
0
 
Lolly-InkCommented:
A programming environment which supports JavaScript files (eg. SVG, HTML) should support calling functions between the JavaScript files if you include them together.

For example, in Test.svg:
<script xlink:href="script/Library.js" language="JavaScript"/>
<script xlink:href="script/Constants.js" language="JavaScript"/>

Another example, in Test.html:
<script src="script/Library.js" type=text/javascript></script>
<script src="script/Constants.js" type=text/javascript></script>

Based on the examples above, a function in Library.js can call any function in Constants.js and a function in Constants.js can call any function in Library.js.
0
 
DauheeCommented:
unfortunately they are being run as .js files outside of the web :)
0
 
Michel PlungjanIT ExpertCommented:
If you put them in an HTA you could run them with the security of a standalone .js
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now