JavaScript classes and class inheritance

Before getting started on the EventEmitter class, we need to take a look at another of the ES2015 features: classes. The JavaScript language has always had objects, and a concept of a class hierarchy, but nothing so formal as in other languages. The ES2015 class object builds on the existing prototype-based inheritance model, but with a syntax looking very much like class definitions in other languages.

For example, consider this class we'll be using later in the book:

class Note {    constructor(key, title, body) {        this._key = key;        this._title = title;        this._body = body;    }    get key() { return this._key; }    get title() { return this._title; }    set title(newTitle) { return this._title = newTitle; } get body() ...

Get Node.js Web Development - Fourth Edition 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.