JSFiddle - React, Tailwind, and code Playground

by mattstyles

JavaScript

var Base = function (name) {
  this.name = name
}

var Robot = function (name) {
  Base.call(this, name || 'Robot')
}

Robot.prototype = Object.create(Base.prototype)
Robot.prototype.sleep = function (time) {
  console.log(this.name, 'is sleeping...')
    setTimeout(() => {
      console.log(this.name, 'is now awake again.')
    }, time || 100)
}
Robot.prototype.patrol = function () {
  console.log(this.name, 'is patrolling.')
}

var Flyer = function (name) {
  Base.call(this, name || 'Flyer')
}

Flyer.prototype = Object.create(Robot.prototype)
Flyer.prototype.patrol = function () {
  console.log(this.name, 'is starting an airborne patrol.')
}

var robot = new Robot()
var flyer = new Flyer()

robot.sleep(100)
robot.patrol()

flyer.sleep(100)
flyer.patrol()