Chapter 12 of 16All chapters
Chapter 12 of 16
Classes
Syntax over prototypes, and what it hides.
Defining one
class defines a type, constructor runs on new, and methods sit in the body without the function keyword. Fields can be declared directly, and a leading # makes one truly private.
- extends inherits, and super() calls the parent constructor first.
- static members belong to the class rather than to instances.
Prototypes underneath
Classes are a cleaner way to write JavaScript's prototype system. Every object links to a prototype, and a property not found on the object is looked for there next.