JavaScript: Class Expression
Class can be created by expression form:
const x = class {body};
const x = class name {body};
Class expression returns a value. Can be called inline.
// class is a expression. it returns a value. can be called inline console.log( new (class Bb { constructor(x) { this.p = x; } })(3), ); // Bb { p: 3 }
The name in
x = class name {body};
is optional. When given, it allows you to refer to itself inside the class body, but the name is not exposed outsite of it.
// the name of a named class expression is only available inside the class body const Dd = class Cc { constructor(x) { this.p = x; } }; new Cc(3); // error: Uncaught ReferenceError: Cc is not defined