Is it possible to create a new instance of self/this using ES6 inside a static method? For example;
class myClass {
static model() {
return new this;
}
}
Is there a recognised pattern for this type of scenario?
Many thanks.
Is it possible to create a new instance of self/this using ES6 inside a static method? For example;
class myClass {
static model() {
return new this;
}
}
Is there a recognised pattern for this type of scenario?
Many thanks.
Yes, this is exactly how you'd do it.
If you don't want subclasses to use the subclass constructors, refer to your class by name explicitly, similar to accessing other static methods.