Solved

How import another module into .js script

Posted on 2008-06-24
7
1,235 Views
Last Modified: 2011-09-20
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
Comment
Question by:petrph
7 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 21862710
file2:
document.write('<script src="file1.js"><\/script>')
MyFun();
0
 

Author Comment

by:petrph
ID: 21863691
Thank, but this is , what I can't use - not in  web page -so no document.write. Simple running .js file.
0
 
LVL 7

Accepted Solution

by:
Dauhee earned 180 total points
ID: 21863819
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 21864998
What do you mean "Not in a web page"?
0
 
LVL 16

Expert Comment

by:Lolly-Ink
ID: 21870782
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
 
LVL 7

Expert Comment

by:Dauhee
ID: 21872338
unfortunately they are being run as .js files outside of the web :)
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 21872722
If you put them in an HTA you could run them with the security of a standalone .js
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java script read and write file - save as location 8 45
would you please explain me the conditional part ? 4 22
Javascript Form Change 5 23
Else condition 9 19
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question