Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

277
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda