- i am new to js
- i am trying to get the value of js functions from one file to another js file
- providing code below
can you update my code
file1.js function fileOne() { return value1; }
file2.js function fileTwo() { /* pass value of fileOne function */ }
Asked
Active
Viewed 54 times
0

Teemu
- 22,918
- 7
- 53
- 106
-
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions – Teemu Jun 27 '16 at 16:46
-
1` var val = fileOne(); fileTwo(val) { alert(val); }` – Legends Jun 27 '16 at 16:46
-
Are both these files being loaded in a html/php file? – Hozeis Jun 27 '16 at 16:50
-
@JoseRodrigues in a html file – Jun 27 '16 at 18:14
1 Answers
0
In your html file make sure you have both js file loaded before you refer to the functions you are trying to use.
First load files
<script src="file1.js"></script>
<script src="file2.js"></script>
Then call functions
<script>
var returnOne = fileOne();//call function from file1.js
fileTwo(returnOne); //call function two from file2.js
</script>

Hozeis
- 1,542
- 15
- 36
-
-
You would create the namespace inside of file1.js and file2.js to keep functions from file2 overwritting functions from file1. look at http://stackoverflow.com/a/881556/4825796 for more – Hozeis Jun 27 '16 at 18:47