JavaScript classes
JavaScript classes, inheritance, and class syntax
Learn JavaScript classes with focused lessons on class syntax, constructors, methods, inheritance, static members, private and protected fields, extending built-in classes, instanceof, mixins, and prototypes.
Class lessons and concepts
Constructor functions before classes
Understand object construction with new before moving into class syntax and instance initialization.
Outcome: Connect class constructors to the older function-based object model.
- JavaScript constructor
- new operator
- object instances
Prototype inheritance
Study the prototype chain because JavaScript classes are built on top of prototypal inheritance.
Outcome: Understand inherited methods before using class extends syntax.
- prototype inheritance
- prototype chain
- prototypal inheritance
Function prototype
Learn how constructor functions use prototype to share behavior across object instances.
Outcome: See the mechanism that class methods compile down to conceptually.
- function prototype
- constructor prototype
- shared methods
Class basic syntax
Write class declarations with constructors, methods, fields, and reusable object blueprints.
Outcome: Create readable class-based models for users, products, widgets, and services.
- JavaScript classes
- class syntax
- constructor method
Class inheritance
Use extends and super to build specialized classes from base classes without duplicating behavior.
Outcome: Model related object types while keeping shared behavior in one place.
- class inheritance
- extends JavaScript
- super JavaScript
Static properties and methods
Attach behavior to the class itself for factories, helpers, counters, configuration, and shared utilities.
Outcome: Distinguish instance behavior from class-level behavior.
- static methods
- static properties
- class utilities
Private and protected members
Use privacy patterns and private fields to control internal state and prevent accidental outside access.
Outcome: Design classes with clearer public interfaces and safer internal state.
- private fields
- protected properties
- encapsulation
Extending built-in classes
Extend built-in types carefully and understand the tradeoffs of custom arrays, errors, and platform objects.
Outcome: Know when built-in subclassing is useful and when composition is cleaner.
- extend built-in classes
- custom Error
- subclass Array
Instanceof and class checks
Check whether values belong to a constructor or class hierarchy with instanceof and related patterns.
Outcome: Validate class instances without confusing prototypes, primitives, and plain objects.
- instanceof
- class checking
- constructor check
Mixins
Compose behavior across classes with mixin patterns when single inheritance is too restrictive.
Outcome: Share behavior across unrelated classes without forcing an inheritance tree.
- JavaScript mixins
- class composition
- reusable behavior
Custom errors
Extend Error to create named error classes with clearer failure types and handling paths.
Outcome: Create class-based error types for validation, network, and domain failures.
- custom errors
- extend Error
- error classes
Native prototypes
Understand native prototypes so class code fits into JavaScript's broader inheritance model.
Outcome: Reason about methods inherited from Array, Object, Function, and other built-ins.
- native prototypes
- built-in prototypes
- prototype methods