Javascript

Home Load Console Selectors CSS Form Strings If Else Array Reg Exp Date & Time setTimeout JSON Loops Objects Animation Fat Arrow Class Import IIFE undefined Tabulator.js ES6 Event Listeners AJAX Hide Elements Create Elements Checkbox ejs
O O

Weather Controls

Time Of Day
Rain
Wind Speed
Wind Direction
Clouds

Javascript : Class

2022-07-19

Overview

Class was added in ES6. It is using prototype JS under the hood.

ES6 Javascript

class CoffeeMaker {
    Constructor(grinder, pump, heater) {
      this.grinder = grinder;
      this.pump = pump;
      this.heater = heater;
    }
    brew () {
      console.log("Brewing coffee");
      this.grinder.grind();
      this.heater.on();
      this.pump.pump();
    }  
}

Prototype Javascript

var CoffeeMaker = function(grinder, pump, heater) {
  this.grinder = grinder;
  this.pump = pump;
  this.heater = heater;
}
CoffeeMaker.prototype.brew = function () {
  console.log("Brewing coffee");
  this.grinder.grind();
  this.heater.on();
  this.pump.pump();
}

Reference

https://youtu.be/_OGGsf1ZXMs