JS: 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 outside 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
JavaScript, Constructor, Class
- JS: Constructor and Class
- JS: this (binding)
- JS: Constructor
- JS: prototype (property)
- JS: new (operator)
- JS: instanceof (operator)
- JS: constructor (property)
- JS: typeof, .instanceof, .constructor
- JS: Class
- JS: Class Syntax
- JS: Class Expression
- JS: typeof Class
- JS: static (keyword)
- JS: extends (keyword)
- JS: super (keyword)
- JS: Define a Class Without class