I have a JS file located in directory c:\myJSfiles\FileNumberOne.xyz
//c:\myJSfiles\FileNumberone.xyz
var 1 = ThisValue1;
var 2 - ThisValue2;
and so on
In the same root directory, I have second JS file c:\myJSfiles\FileNumberTwo.xyz which I want to import the values of the variables from FileNumberOne.xyz
//file: c:\myJSfiles\FileNumberTwo.xyz
var A = "c:\myJSfiles\FileNumberOne.xyz", var 1;
var B = "c:\myJSfiles\FileNumberOne.xyz", var 2;
How would I do this?
-
Would be great if you can share the exact extension of the file instead of saying "xyz" .Raghu– Raghu2013年10月03日 18:36:41 +00:00Commented Oct 3, 2013 at 18:36
1 Answer 1
var 1 makes no sense, I assume you did it as an example only. Otherwise if you declare something in the first referenced script on the page, it will automatically be available in the second.
for example if you have in
<script src="Script1.js"></script>
line
var something = "hello"
you can reference the second script after the first
<script src="Script2.js"></script>
and in that script use that variable
alert(something); // will display hello
answered Oct 3, 2013 at 18:39
Comfortably Numb
39.9k17 gold badges82 silver badges147 bronze badges
Sign up to request clarification or add additional context in comments.
5 Comments
ddawson7
Since I am a beginner, I am confused about applying your answer to my situation. var1 = ThisValue1 which is a number that changes frequently as is var 2. Would you be so kind as to write your answer so I can see how ThisValue1 makes it into the second JS file...Thanks
ddawson7
Please note, this JS is not a webpage.
Comfortably Numb
@ddawson7 were do you run your JS then - what environment?
ddawson7
Within a charting application
Comfortably Numb
Could you please elaborate? What is the application name, what technologies does it use? Windows, Web, etc.?
lang-js