I want to call Javascript file from my Javascript program without using HTML. How can i do this without need of html file to integrate my js files ?
Asked
Active
Viewed 390 times
0
-
Are you trying to load another script, call a function from a loaded file, bundle your modules into a single file, ...? – ssube Jan 25 '16 at 15:44
-
5Possible duplicate of [Include a JavaScript file in another JavaScript file?](http://stackoverflow.com/questions/950087/include-a-javascript-file-in-another-javascript-file) – Zippy Jan 25 '16 at 15:46
1 Answers
0
If you are running this script outside of a browser, for example using nodejs, which runs on Chrome's V8 javascript engine: http://nodejs.org/. In nodejs you can create a module and export this module to use in another script. See the following example using nodejs to run:
file1.js:
var exports = module.exports = {};
exports.f1 = function() {
console.log('This is from file1.js');
};
file2.js:
var f = require('./file1.js');
function f2() {
console.log('This is from file2.js');
}
f2();
f.f1();
Executing the file2.js using nodejs command the output will be:
This is from file2.js
This is from file1.js
But if you are using a browser you can see this: https://stackoverflow.com/a/4634669/2137684

Community
- 1
- 1

Alisson Alvarenga
- 648
- 5
- 12