我有一个看起来像这样的函数:
module.exports = myFunction() {
//do some stuff
}
我可以使用 var myFunction = require(.thepath.js)
但是我如何从创建它的文件中访问它。
我试过 myFunction()
和 this.myFunction()
但都不起作用。
谢谢
最佳答案
你可以将它保存到一个变量然后像这样导出变量:
// Create the function
const myFunction = function() {
}
// Call the function
myFunction();
// Export the function
module.exports = myFunction
关于javascript - JS - 如何访问同一文件中的 module.exports 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45952967/