I've found many posts on class inheritance but not about this specific problem with changing properties on static classes.
Here is the problem: I'm trying to implement class inheritance on JavaScript on a static class that will have some general static methods and will be extended by child classes, static as well. Child classes may add more static methods and will change a configuration object. None of them will be instantiated so I assume that I can't create the body property on the constructor as it will not be called. I have the following code working but I think it might not be the right way to do this.
Could you suggest a better alternative?
class Animal{
static get body(){
return {
legs: null,
head: 1,
}
}
static getLegs(){
return this.body.legs;
}
static getHead(){
return this.body.head;
}
}
class Ant extends Animal{
static get body(){
return {
legs: 6,
head: 1,
}
}
}
class Monster extends Animal{
static get body(){
return {
legs: 4,
head: 2,
}
}
}
console.log(Animal.getLegs(), Animal.getHead());
console.log(Ant.getLegs(), Ant.getHead());
console.log(Monster.getLegs(), Monster.getHead());