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?