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

278
Vistas
export default new object

Is it guaranteed that export default new object(), where object is some kind of type (e.g. Date), returns the same object all the time?

// date.js
export default new Date()
// foo.js
import date from './date'
// bar.js
import date from './date'

Can it be expected that date in foo.js and date in bar.js are equivalent. So import date from './date' is a singleton?

Would the above export default new Date() be equivalent to module.exports = new Date() for pre-es6 era?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Yes, it will always be the same object. In any given run of a script, you can assume that the top level of a file, eg:

// date.js
export default new Date()

will run exactly once, and no more, if the file gets imported. Further imports of that file will result in date.js's exports being importable, but will not run date.js again.

over 4 years ago · Santiago Trujillo 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