Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

ES6 Classes

node v4.9.1
version: 1.0.0
endpointsharetweet
Classes are a shorthand that make it easier to work with JavaScript's existin prototypal inheritance.
class Shape { constructor(sides) { this._sides = sides; } get sides() { return this._sides; } }
class Triangle extends Shape { constructor(...angles) { super(3) this._angles = angles; if (angles.length !== 3 || angles[0] + angles[1] + angles[2] !== 180) throw RangeError("Triangles must have 3 sides at angles equaling 180"); } get angles() { return this._angles; } }
(new Triangle(90,45,45)).sides
Loading…

no comments

    sign in to comment