在JavaScript中添加外部JavaScript文件 [英] Adding external javascript file in javascript

查看:37
本文介绍了在JavaScript中添加外部JavaScript文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Electron程序,并希望在主要过程中使用一些javascript类.我希望将这些类放在不同的文件中,并将它们包含在脚本中.

I am writing an Electron program and want to use some javascript classes in the main process. I would prefer to have those classes in different files and include them inside of the script.

我通常通过在html文件中同时添加脚本和类来完成此操作,但是由于它是主要过程,因此没有html文件.

I usually did this by just adding both, the script and the classes inside the html file but since it is the main process there is not html file.

问题是否可以在其他javascript文件中包含外部javascript文件?

Question Is it possible to include an external javascript file in a different javascript file?

推荐答案

由于电子基于 node ,因此您可以在您的主要流程JS文件以及您的项目使用的任何JS文件中.

Since electron is node based, you can use require both in your main process JS file and in any JS file your project uses.

// main.js or something
let myModule = require("./myModule");

// myModule.js
....
module.exports = function() {}; // or whatever you want to share with main.js

这篇关于在JavaScript中添加外部JavaScript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆