I have two classes defined, say Animal and Rabbit. Rabbit extends Animal and has some additional methods apart from those defined in Animal.
When the user runs my app, an instance of Animal is created (say myAnimal). Then depending on something that the user does, I may need to "enhance"/cast myAnimal into the inherited class Rabbit. Is this possible in Modern JavaScript so the additional methods defined in Rabbit may now be available to myAnimal?
@Etheryte 's suggestion worked. I defined a static method fromAnimal in Rabbit which creates a new Rabbit, sets properties of given Animal (myAnimal) and returns that instance. It includes all processing that myAnimal has undergone so far. Thank you.
no you can not.
other way, you can create an instance of Rabbit - myRabbit with properties of myAnimal. (comment of @Etheryte above)
or use decorator of Typescript