I am trying to create a static method that basically creates an instance of the class that made the call automatically.
In this example, I would like class A to create an instance of itself. How can this be done? The below code gives an error when executed.
class Model {
static find(someVar) {
let inst = new this.constructor[this.constructor.name]()
// Do some extra stuff with the instance
return inst
}
}
class A extends Model { }
A.find()
let inst = new this();should work fine: jsfiddle.net/khrismuc/fu3jar8h