I have an Animal Object that looks like this:
AnimalObject {attributes: {…}, locations: {…}}
Animal Object Class:
export default class AnimalObject {
constructor(apiResult, included) {
this.attributes = apiResult.attributes;
this.locations = apiResult.locations;
...
}
I now have a specific AnimalObject called FishObject that has some fish related methods.
export default class FishObject extends AnimalObject {
getFood(){
const foods = this.getFishFood(this.attributes)
return foods
}
talk(){
return "blub"
}
}
Is there a way in javascript that I can cast a list of Animal Objects [{AnimalObject}, {AnimalObject}]
into Fish objects? I want to map through the AnimalObject list and call a fish method.
--Update: I'm most likely going to instantiate with the Fish class...