[英]Have a function from a module be exported in another module?
I have a fairly large function in my module (./myMainModule.js) that I would like to be packaged in a separate module (./mySubModule. I'm trying to figure out how to require(mySubModule) and then have a function from mySubModule be used as a function in myMainModule. 我的模块(./myMainModule.js)中有一个相当大的函数,我希望将其打包在一个单独的模块中(./mySubModule。我试图弄清楚如何需要(mySubModule),然后有一个函数来自mySubModule的代码可用作myMainModule中的函数。
I've tried to export 我尝试出口
mainFunction: mySubModule.subFunction(params), mainFunction:mySubModule.subFunction(params),
but it's saying the params are not defined. 但这是说参数没有定义。
//myMainModule.js
const mySubModule = require("./mySubModule)
module.exports = {
mainFunction: mySubModule.subFunction(params),
}
//----------
//mySubModule.js
module.exports {
subFunction: function(params) {
console.log(params);
}
}
I'm getting params is not defined when assigning the function in myMainModule. 我在myMainModule中分配函数时未定义参数。
const subModule = require("./subModule");
module.exports = {
mainFunction: subModule.subFunction,
// This works ^^
//mainFunction : subModule.subFunction(params),
// Not this ^^
}
My linter was complaining that my params were not defined. 我的小子抱怨我的参数没有定义。 I was actually calling the function when I should have been just referencing it.
我实际上应该在应引用该函数时才调用它。 I did not need to worry about the parameters.
我不需要担心参数。
I was actually calling the function and that's why my linter was saying my params were not defined. 我实际上是在调用该函数,这就是为什么我的小子说我的参数没有定义的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.