Skip to Content
JavaScript
book

JavaScript

by T. J. Crowder
July 2020
Intermediate to advanced content levelIntermediate to advanced
608 pages
15h 43m
English
Wrox
Content preview from JavaScript

4Classes

In this chapter you'll learn how class syntax works for creating JavaScript constructors and associated prototype objects. We'll compare and contrast the new syntax with the old, highlight that it's still the same prototypical inheritance JavaScript is famous for, and explore how powerful and simple the new syntax is. You'll see how to create subclasses, including subclasses of built-ins (even ones that can't be subclassed in ES5 and earlier like Array and Error), how super works, and what new.target is for and how to use it.

This chapter doesn't cover features that are coming in ES2020 or ES2021 like public class fields, private class fields, and private methods. See Chapter 18 for coverage of those.

WHAT IS A CLASS?

Before looking at the new syntax, let's address the elephant in the room: JavaScript doesn't really have classes, does it? It just emulates them with prototypes, right?

That's a popular perspective, because people confuse ...

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.
Start your free trial

You might also like

Advanced JavaScript

Advanced JavaScript

Zachary Shute

Publisher Resources

ISBN: 9781119367956Purchase book