Clone and edit this document
Runkit
Runkit
home page
user forum
new notebook
clone notebook
download notebook
support & documentation
log in
sign up
new notebook
help & feedback
clone this notebook
download this notebook
Sign In
Sign Up
ES6 Classes
node v4.9.1
version:
1.0.0
endpoint
share
tweet
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