0
  • 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 */ }

Teemu
  • 22,918
  • 7
  • 53
  • 106

1 Answers1

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
  • thanks for your reply...can you give an example using name space –  Jun 27 '16 at 18:43
  • 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