• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1249
  • 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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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