R
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.6.1
node v0.10.48
node v0.12.17
node v4.6.1
node v5.12.0
node v6.9.2
version:
1.0.0
releases
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
no comments
sign in
to comment
running
Clone and edit this document