【发布时间】:2017-07-15 03:03:36
【问题描述】:
我正在运行一个电子应用程序,其中我的index.html 页面由scripts.js 中的函数更新。
我正在尝试通过将函数“移动”到同一 js 目录中的单独文件中来清理 scripts.js 文件,但每当我这样做并将该函数导入回 scripts.js 以在render() 方法,不起作用。
例如,我将currencyExchange() 函数放入名为currencyAPI.js 的单独文件中:
var currencyExchange = function(){
//code here
}
module.exports.currencyExchange = currencyExchange
然后,我将它导入到我的scripts.js 文件中:
var currency = require(./currencyAPI.js);
然后在我的render() 函数中调用它,如下所示:
function render(){
// ...
setInterval(currency.currencyExchange, 1500)
}
但是,当运行currency.currencyExhchange 时,它说该文档未定义。
这是我的app 中的scripts.js 文件
【问题讨论】:
-
“不起作用”什么也没告诉我们。更具体。
-
@jfriend00 这个问题也被标记为 Electron,它是一个 npm 模块,它提供了一个简单的 Chromium fork,您可以使用它来编写桌面应用程序。例如,Electron(在 BrowserWindow 内)使您能够使用文档和窗口。
标签: javascript node.js electron