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

112
Visualizações
Javascript Ellipsis and overwriting object properties

I have a function that takes in input a config file; this config file is in fact an object, something like

file first.js

// first config file

const common = require(../common)

// function that returns random day,month,year
const { day, month, year } = time.getDate()

module.exports = {
    ...common,

    dayToChoose: day,
    monthToChoose: month,
    yearToChoose: year,

    [other data]
}

since I can have different versions of this config file, each of them named differently (second.js, third.js, etc. with different data each), I created a "basic" configuration common to all of those files.

common.js is a config file that contains some data.

My question is: can common.js contain something like

const { commonDay, commonMonth, commonYear } = time.getDate()

module.exports = {
    dayToChoose: commonDay,
    monthToChoose: commonMonth,
    yearToChoose: commonYear
}

and put something in my first config file that says "if day, month, and year already exists, take those data, otherwise take the data present in the first.js file" ?

Something like

// first config file

const common = require(../common)

// function that returns random day,month,year
const { day, month, year } = time.getDate()

module.exports = {
    ...common,

    dayToChoose: dayToChoose || day,        // error: dayToChoose is not defined
    monthToChoose: monthToChoose || month,  // like above
    yearToChoose: yearToChoose || year,     // like above

    [other data which varies]
}

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