我在旧代码库中有一段代码,其中包含嵌套的module.exports
,如下所示。我以前没有见过这样的导出形式。有人可以解释一下或至少指出我正确的文章吗?
module.exports = function something(options) {
someMethod = new func1(options);
module.exports.anotherFunc = function (req, res) {
someMethod.anotherFunc1(req, res);
};
module.exports.func1 = someMethod.func3;
return function func4(req, res, next) {
someMethod.anotherFunc1(req, res);
next();
};
};
最佳答案
这可能是尝试动态生成模块以便在应用程序中共享全局状态,但是我不清楚如何导入此类模块。我认为这可能是糟糕的设计。从外观上看,这些内部 exports
语句看起来完全没有必要。
关于javascript - 嵌套 module.exports 的说明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53257266/