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

123
Vistas
Suppose a class object has related properties, is there a better way to initialize than hard-code the relationship?

I have a Budget class with an annual, monthly, and weekly property. Is there a better way to do it than below?:

class Budget{
    //based on choice, the initializer assigns, then calculates the two other properties
    constructor(value, choice) {
        this.value = value;
        this.choice = choice;
        this.annual = 0;
        this.monthly = 0;
        this.biweekly = 0;
    }

    initialize() {
        this.choice == 1 ? (this.annual = this.value,
                            this.monthly = this.annual/12,
                            this.biweekly = this.annual/52) :
        this.choice == 2 ? (this.monthly = this.value,
                            this.annual = this.monthly*12,
                            this.biweekly = this.annual/52):
        (this.biweekly = this.value,
         this.annual = this.biweekly*52,
         this.monthly = this.annual/12);
                            
    }


}
about 4 years ago · Juan Pablo Isaza
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