Would you like to clone this notebook?

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

Cancel

ES2015 Class Example

node v10.17.0
version: 2.0.0
endpointsharetweet
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