Call From Module.export ; A Function That Is Inside The Same Module.export
I need help about this piece of code. What i am trying to do, is to call a function in the "root" of a module.export. But the call provide from a function inside the same module.export. Here is what I got :
From another script, I have the function "base-execute" called. What i'm trying to do, is to call the function "Tocall-Function" just after. Is this possible ?
module.exports.main = {
Part1 : {
Sub1 : {
base-execute(){
// Some code and then call the "Tocall-Function" //
}
},
Sub2 : {...}
},
Part2 : {...}
Tocall-Function(){
//Another piece of code//
}
}
I tried 'this.Tocall-Function'. But the 'this' itself return only what is written right before the "base-execute" function (what is inside the Sub1 part).
I can access variables that are not inside the module.exports.main. But I can't call it itself.
I can't find something working in my case. If someone can help me out that will be great !
Thank you for reading.
Answer
You can define main
separately from export, and call the function you want to call with main.TocallFunction();
const main = {
Part1 : {
Sub1 : {
baseExecute() {
main.TocallFunction();
// Some code and then call the "Tocall-Function" //
}
},
Sub2 : {}
},
Part2 : {},
TocallFunction() {
//Another piece of code//
}
};
exports.main = main;
Related Questions
- → Maximum call stack exceeded when instantiating class inside of a module
- → Browserify api: how to pass advanced option to script
- → Node.js Passing object from server.js to external modules?
- → gulp-rename makes copies, but does not replace
- → requiring RX.js in node.js
- → Remove an ObjectId from an array of objectId
- → Can not connect to Redis
- → React: How to publish page on server using React-starter-kit
- → Express - better pattern for passing data between middleware functions
- → Can't get plotly + node.js to stream data coming through POST requests
- → IsGenerator implementation
- → Async/Await not waiting
- → (Socket.io on nodejs) Updating div with mysql data stops without showing error