Lesson 27. Classes

After reading lesson 27, you will

  • Understand the syntax for defining classes
  • Know how to instantiate classes and how to use constructor functions
  • Know how to export classes from modules
  • Understand that class methods are not bound
  • Know how to assign class and static properties

Classes are little more than syntactic sugar for declaring a constructor function and setting its prototype. Even with the introduction of classes, JavaScript isn’t statically or strongly typed. It remains a dynamically and weakly typed language. However, classes do create a simple self-contained syntax for defining constructors with prototypes. The main advantage over constructors, though, besides syntax, is when extending classes, which we’ll get ...

Get Get Programming with JavaScript Next now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.