Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

134
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda