Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

111
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!