I am creating a class and its subclasses, where I am required to call a static method of the parent to return a child instance.
class Animal{
static findOne(){
// this has to return either an instance of Human
// or an instance of Dog according to what calls it
// How can I call new Human() or new Dog() here?
}
}
class Human extends Animal{
}
class Dog extends Animal{
}
const human = Human.findOne() //returns a Human instance
const day = Dog.findOne() //returns a Dog instance
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…