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
ES2015 Class Example
node v10.24.1
version:
2.0.0
endpoint
share
tweet
class Elevator { constructor(name, floorNumber, status) { this.name = name; this.floorNumber = floorNumber; this.status = status; } get info() { return `Elevator ${this.name} - Floor ${this.floorNumber}, Status ${this.status}`; } get floor() { return this.floorNumber; } moveUp() { this.floorNumber++; } moveDown() { this.floorNumber--; } moveToFloor(floorNumber) { this.floorNumber = floorNumber; } } const e1 = new Elevator("e1", 1, "operating"); const e2 = new Elevator("e2", 5, "operating"); console.log(e1.info); console.log(e2.info); e1.moveUp(); console.log(e1.info); e2.moveDown(); console.log(e2.info); e1.moveToFloor(20); console.log(e1.floor);
More info: * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes
Loading…
no comments
sign in
to comment