创建节点模块 "xxx is not a function"
Create node module "xxx is not a function"
我正在创建一个 NW.js 应用。
我创建了一个节点 "sub-module"(不知道应该如何称呼)update.js
:
function Updater() {
if (!(this instanceof Updater)) return new Updater();
console.log("init");
}
Updater.prototype.CheckUpdate = function() {
console.log("Checking for update");
};
Updater.prototype.SetTimer = function() {
console.log("set timer");
};
Updater.prototype.destroy = function destroy() {
this.remove();
return true;
};
module.exports = Updater;
我在主脚本中这样调用它,run.js
:
var updater = require('./update');
updater.CheckUpdate();
updater.SetTimer();
但我的日志文件中出现错误(上面未显示):
"TypeError: updater.CheckUpdate is not a function"
我不确定我做错了什么...
CheckUpdate 和 SetTimer 是 Updater.prototype 的属性,而不是 Updater。
所以试试这个:
var Updater = require('./update');
var updater = new Updater();
updater.CheckUpdate();
updater.SetTimer();
我正在创建一个 NW.js 应用。
我创建了一个节点 "sub-module"(不知道应该如何称呼)update.js
:
function Updater() {
if (!(this instanceof Updater)) return new Updater();
console.log("init");
}
Updater.prototype.CheckUpdate = function() {
console.log("Checking for update");
};
Updater.prototype.SetTimer = function() {
console.log("set timer");
};
Updater.prototype.destroy = function destroy() {
this.remove();
return true;
};
module.exports = Updater;
我在主脚本中这样调用它,run.js
:
var updater = require('./update');
updater.CheckUpdate();
updater.SetTimer();
但我的日志文件中出现错误(上面未显示):
"TypeError: updater.CheckUpdate is not a function"
我不确定我做错了什么...
CheckUpdate 和 SetTimer 是 Updater.prototype 的属性,而不是 Updater。 所以试试这个:
var Updater = require('./update');
var updater = new Updater();
updater.CheckUpdate();
updater.SetTimer();