Class Expressions
Class expressions are useful to create dynamic classes at runtime based on, for example, properties you read from a file, database, or user-provided input. Imagine creating a class factory function that will create and return a class—that’s a good place to use a class expression.
JavaScript supports both a class statement—which you use to define a class—and a class expression. The two key differences between a class expression and a class statement are
-
The class name is optional for class expressions but required for class statements.
-
The class expression should be treated as an expression—that is, it should be returned, passed to another function, or be stored in a variable.
Class statements are more common than class expressions, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access