In JavaScript, it's possible to assign a ES6 class
to a variable (MDN: Class Expression):
const Foo = class {
constructor() {}
bar() {
return "Hello World!";
}
};
So, say I have a class called Animal
that looks like this:
class Animal {
// Properties and methods for the `Animal` class...
}
Then assigned a class to a static
property, like this:
class Animal {
// Properties and methods for the `Animal` class...
static Human = class {
// Properties and methods for the `Animal.Human` class...
};
}
For example, to use like this:
const alex = new Animal.Human();
This is not something I've seen done in practice, so would this be bad practice?