JSFiddle - React, Tailwind, and code Playground

by mattstyles

JavaScript

class Base {
  constructor (name) {
    this.name = name
  }
}

class Robot extends Base {
  constructor (name)  {
    super(name || 'Robot')
  }

  sleep (time) {
    console.log(this.name, 'is sleeping...')
    setTimeout(() => {
      console.log(this.name, 'is now awake again.')
    }, time)
  }
  
  patrol () {
    console.log(this.name, 'is patrolling.')
  }
}

class Flyer extends Robot {
  constructor (name) {
    super(name || 'Flyer')
  }

  patrol () {
    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()