我有文件导出'item-state-manager.js':
module.exports.aggregate_states = function (member_states) { console.log(member_states); }
其他文件应导入此模块并使用函数'aggregate_states':
var aggregate_states = require("./item-state-manager.js") module.exports.saveItem = function () { var aggregate = aggregate_states("state"); }
但我收到错误:
TypeError: aggregate_states is not a function
我导入'item-state-manager.js'错了吗?
据我所知,require返回module.exports对象.
如果aggregate_states是您要导出的唯一函数,请使用此函数.
module.exports = function (member_states) { console.log(member_states); }
否则像这样导入它.
var aggregate_states = require("./item-state-manager.js").aggregate_states;