I have a parent class with a bunch of children, each with very specific methods.
I need to loop through the array and basically each element will need to access a different child class. Is there any way to do this dynamically?
My classes currently look like this:
export default class MyParent {
constructor (something) {
// do constructor things
}
someMethod(param) {
// do something
}
}
.
.
.
export default class MyChildClass extends MyParent {
constructor (something) {
super(something)
}
someMethod(param) {
// do something in overwritten method
}
}
So basically I have a bunch of child classes, and now I need an array to go through them. Each element of that array will go through a different one of them.
export default function goThroughClasses (myArray) {
const parentClass = new ParentClass(something)
return myArray.map(arr => {
// I would like this to go through all the different child methods instead of just the parent class
// Note: the array does have data which would indicate which one
// it should go through
return parentClass.someMethod(arr)
})
)
}
How can I do this?