Classes

Overview

  • Introduced in ECMAScript 2015 with the release of ES6
  • Many OOP languages have classes (Java, Python, C++)
  • Programmers decided they wanted the functionality of classes that other languages had.
  • Problem was, JavaScript is based a prototype based language as opposed to an Object Oriented Language

What is a Class?

In JavaScript, a class is syntactical sugar for a function that creates an object.

Javascript uses prototypal inheritance: every object inherits properties & methods from its prototype object.

Prototypal Inheritance Link

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain

Classes make thinking about Inheritance easier if you don't come from a previous language

function Auto(numWheels){

   this.numWheels = numWheels

   this.type = type

}

Before classes in JavaScript you had constructor functions that looked like this:

 

Classes

By JD Richards