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

136
Visualizações
Calling a certain variable from a method in JavaScript

I would like to know how I can write a method in such a way that I can later call a variable stored in it.

Of course, after I export and import into another Javascript file, I want to call the variable from the method, but I don't know exactly the syntax and if I have to use 'this'

I also don't know what to return to have all the declared variables available at any time

I want something like

class Security {
  chooseEntrance(FrontEntrance, BackEntrance) {
    FrontEntrance = //some code//
    BackEntrance = //some code//
  }
}

export default Security

And from another file, after import, call something like Security.chooseEntrance(FrontEntrance)

I hope I've set out all the data I need

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can't do that. By typing Security.chooseEntrance(FrontEntrance) you ask to execute the function and not get the variable in the function. We need more context to answer you propely but an answer can be either to store the variable somewhere in the script wich call the function or to create a field in the class Security and retrieve it later with a getter like this:

class Security{
    frontEntrance

    getFrontEntrance(){
        return frontEntrance
    }

    chooseEntrance(FrontEntrance,BackEntrance){
      FrontEntrance=//some code//
      BackEntrance=//some code//
    }

  }
export default Security
about 4 years ago · Juan Pablo Isaza Relatório

0

class Security {
  FrontEntrance;
  BackEntrance;
  chooseEntrance(FrontEntrance, BackEntrance) {
    this.FrontEntrance = FrontEntrance;
    this.BackEntrance = BackEntrance;
  }
}

export default Security;

from some other class you access

const security = new Security();
security.chooseEntrance('', '');


security.FrontEntrance;
security.BackEntrance;
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