I have a class that only requires one instance in my code. Is it better (and convention) to stick with the regular class, constructor and only create one instance of the class or to directly use the class without creating any instances by using static methods and properties? Something like this:
class Foo {
constructor() {
this.bar = []
}
foobar(x) {
this.bar.push(x)
}
}
let foo = new Foo()
Or like this:
class Foo {
static bar = []
static foobar(x) {
this.constructor.bar.push(x)
}
}
The second one takes up less space, but I'm not sure whether it adheres to OOP conventions.