I have a module that I require in another location, here is an example (call this lib.js):
module.exports = {
a:{
someFunc: function()
{
}
},
b:{
someOtherFunc: function()
{
}
}
}
My other file would be like so:
const lib = require('./lib.js');
lib.a.someFunc();
But what if i want to access a.someFunc() from b.someOtherFunc()?
I have tried using this.a.someFunc() but that doesn't work, probably because it's not an instantiated object as such. I have also tried exports.a.someFunc() but that also doesn't work.
So neither of these work:
module.exports = {
a:{
someFunc: function()
{
}
},
b:{
someOtherFunc: function()
{
this.a.someFunc();
exports.a.someFunc();
}
}
}
Is this even possible to do?
You have to define them separatly like this
const a = {
someFunc: function() {
}
}
const b = {
someOtherFunc: function() {
a.someFunc();
}
}
module.exports = {a, b}