<code>class Report {
constructor(Id, destination, station, time = new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })) {
this.Id = Id;
this.destination = destination;
this.time = time;
this.station = station;
}
}
export default Report;
</code>
<code>class Report {
constructor(Id, destination, station, time = new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })) {
this.Id = Id;
this.destination = destination;
this.time = time;
this.station = station;
}
}
export default Report;
</code>
class Report {
constructor(Id, destination, station, time = new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })) {
this.Id = Id;
this.destination = destination;
this.time = time;
this.station = station;
}
}
export default Report;
i was wondering if this a good approach if not, should make a function that gets the current time and use it ?
<code>class Report {
constructor(Id, destination, station, time) {
this.Id = Id;
this.destination = destination;
this.time = time;
this.station = station;
}
static create(Id, destination, station) {
const currentTime = new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
return new Report(Id, destination, station, currentTime);
}
}
export default Report;
</code>
<code>class Report {
constructor(Id, destination, station, time) {
this.Id = Id;
this.destination = destination;
this.time = time;
this.station = station;
}
static create(Id, destination, station) {
const currentTime = new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
return new Report(Id, destination, station, currentTime);
}
}
export default Report;
</code>
class Report {
constructor(Id, destination, station, time) {
this.Id = Id;
this.destination = destination;
this.time = time;
this.station = station;
}
static create(Id, destination, station) {
const currentTime = new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
return new Report(Id, destination, station, currentTime);
}
}
export default Report;
this is an alternative solution but it seems unnecessary , im not sure
New contributor
user26200332 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.