I want to make something like bla.FooBarBaz in JavaScript, but, bla is a class and FooBarBaz is a class, but INSIDE THE bla CLASS. How to do it?
>Solution :
There are no nested classes in ES6 but yes, you can put a second class as a static property on another class, like this:
class Parent {
//code
}
Parent.B = class {
//code
};
or by using extra scope:
var dataClass;
{
class D {
constructor() { }
}
dataClass = class DataClass {
constructor() { }
method() {
var a = new D(); // works fine
}
}
}
But with the help of this proposed class, you can write a single expression or declaration:
class Parent {
//code
static Child = class {
//code
}
};