Solved

How import another module into .js script

Posted on 2008-06-24
7
1,238 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Word Press Fixes to Google Speed Test Issues 2 50
How to open a new browser tab after executing php script 20 49
How does this modal gets closed? 6 41
Drag & Drop Error 5 31
This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

734 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