Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

126
Views
Can I access method within the same export?

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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You have to define them separatly like this

const a = {
  someFunc: function() {

  }
}
const b  = {
  someOtherFunc: function() {
    a.someFunc();
  }
}

module.exports = {a, b}

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!