[Java Script] To call a function in another file

Asked 2 years ago, Updated 2 years ago, 119 views

Please tell me how to call function1 of file2 from file1.

I wish I could only recall that function.

javascript function call

2022-09-22 20:06

1 Answers

You should specify this part because the way you refer to other files is different for each script implementation (JavaScript Launcher).

For browsers:

<script src="other files.js"></script>

There's a way to include it in one HTML.

If Node.js:

//Syntex 1 :
function drawCircle() {
  ...
}
exports.drawCircle = drawCircle;

//Syntex 2 :
exports.fibonacchi = function(num) {
  return -1;
};

//Syntex 3 :
var show = exports.show = function() {
  console.log('hi');
}

Export it like this,

var userModule = require('./user_module');

I write it down like this.


2022-09-22 20:06

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.