假设我在我的Node.Js应用程序的exports
中有以下validate.js
函数:
exports.stopwordsClean = function () {
return function(req, res, next){
console.log("validating...");
}
};
我明白,从另一个文件引用这个函数我会首先require
这个文件,然后使用validate.stopwordsClean()
但是如何从同一个文件中引用它呢? this.stopwordsClean()
不起作用......
exports
是module
中的一个对象。当你写exports.stopwordsClean = function () {..
时,你正在设置stopwordsClean
对象的属性exports
。因此你可以随时使用
exports.stopwordsClean()
在同一个模块中使用该功能。