I am attempting to create a class in javascript to immitate the defined schema of a java object as opposed to a chaotic/schemaless JSON object. Is it okay to use OR (||) as I did to initialize values if they are missing in the initiation of an instance. For example,
class PlotObj {
constructor(startHour, startMin, endHour, endMin) {
this.startHour =startHour || 0;
this.startMin =startMin || 0;
this.endHour =endHour || 23;
this.endMin =endMin || 54;
}
}
let obj = new PlotObj(null, null, 5, 40)
Or is there a better way to acheive this. I know you can initialize them above the constructor in the class, but I want to be able to pass parameters from any of the positions, like the example shown, where I only pass the 3rd and 4th. I would also like to, of course, be able to send the 1st and 2nd, or 1st and 3rd, and so on, any combination. Thanks!