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

122
Vistas
Having variables in the constructor vs in the actual class?

The first of the below code examples is what I am doing today, where I initialise the global variables in the constructor.

But would there be any harm in moving the global variables out in the class, as seen in the second example?

class Alert {
  constructor(alert) {
    this.load = JSON.parse('{}');
    this.alert = alert;
    this.#coolDownTime = 0;
  };

  #coolDownTime;
}

vs just doing

class Alert {
  constructor(alert) {
    this.alert = alert;
  };

  #coolDownTime = 0;
  #load = JSON.parse('{}');

}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

JavaScript classes are functions, which are objects. (POOP (prototype object-oriented programming)).

Here's an interesting concept, since JavaScript classes are functions, then what do we actually write? JavaScript ES6 classes are just syntactic sugar for prototypes. This means, that both of your ideas are actually the same.
This is exactly how creating a method works.

Here is a good reference: Are ES6 classes just syntactic sugar for the prototypal pattern in Javascript?

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