Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

131
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda