Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
"enhance" object to inherited class javascript

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?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

@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.

about 4 years ago · Juan Pablo Isaza Report

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!