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

130
Vistas
Is it practical to store state in object literals using modules?

I am using JS modules to organise shared code in my app. The problem I have found with classes is that you need to keep track of the created instance and get it to where it is needed later. However since a module is only imported once is it not easier to store data in an exported object and import again as needed? Ie:

const serviceTestObject = {

  date: "",

  setDate: function() {
    console.log("Setting")
    this.date = new Date().toLocaleTimeString()
  },

  getDate: function() {
    console.log(this.date, ": Date/Time object literal")
  }
  
}

export default serviceTestObject

So when I import this again I get the original value as expected where/when setDate() was called. Is there a potential problem with this and/or reason I should be using JavaScript classes?

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