我在使用带节点的外部jQuery文件时遇到了问题。我有几个我需要运行的功能,但它不起作用。我创建了一个简单的函数来测试,但我一直得到的错误信息是TypeError:Object#没有方法'alert_helloworld'。这是我的两个文件:
example.js
var jsdom = require('jsdom');
var templateparser = require('./templateparser.js');
var test = templateparser.alert_helloworld();
templateparser.js
function alert_helloworld(){
console.log("Hello World");
return false;
}
帮助!
答案 0 :(得分:1)
您需要在templateparser.js中使用exports对象:
exports = exports || {};
exports.alert_helloworld = function(){
console.log("Hello World");
return false;
}
答案 1 :(得分:0)
module.exports.alert_helloworld = function alert_helloworld(){
console.log("Hello World");
return false;
};
实际导出所需的功能非常重要。默认情况下,node.js模块包装在它们自己的独立模块范围内。