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

129
Views
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
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!