Solved

How import another module into .js script

Posted on 2008-06-24
7
1,239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…
Suggested Courses

627 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