O'Reilly logo

Hands-On Microservices with Node.js by Diogo Resende

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Classes

JavaScript's classes are syntactic sugar over the inheritance model. They introduced a new way of defining object-oriented inheritance that existed in JavaScript but that new developers were not used to. They also introduced a simpler way of extending and defining an object prototype:

class Rectangle {    constructor (w, h) {        this.w = w;        this.h = h;    }    get area () {        return this.w * this.h;    }    static clone(r) {        return new Rectangle(r.w, r.h);    }}

We just created a Rectangle class, with a constructor to specify dimensions and an area method, too. We also added a static method to clone a Rectangle instance.

Unlike the previous, and still possible, prototype definition, using this syntax will force a stricter development. More specifically: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required