JavaScript Classes ES6

Under the hood, ES6 classes are not something that is radically new:
They mainly provide more convenient syntax to create old-school constructor functions. ~ Axel Rauschmayer


In JavaScript, a class is a kind of function.

*** Scotch io Classes *** | w3 Classes | MDN Classes | Github Sample Classes | ** JS Tuts Class **

In object-oriented programming, a class is an extensible program-code-template for creating objects, providing initial values for state (member variables) and implementations of behavior (member functions or methods).



  class User {

    constructor(name) {
      this.name = name;
    }
  
    sayHi() {
      alert(this.name);
    }
  
  }
  
  // Usage:
  let user = new User("John");
  user.sayHi();


*** JavaScript Info Classes ***

In practice, we often need to create many objects of the same kind, like users, or goods or whatever.
As we already know from the chapter Constructor, operator "new", new function can help with that.
But in the modern JavaScript, there’s a more advanced “class” construct, that introduces great new features which are useful for object-oriented programming.


  class MyClass {
    // class methods
    constructor() { ... }
    method1() { ... }
    method2() { ... }
    method3() { ... }
    ...
  }



Shiffman YT
ES6 The Coding Train | Shiffman 6.3: Constructor Arguments with Classes in JavaScript - p5.js Tutorial




Get Skeleton CSS Fun and Games

Anchor button Anchor button
Last Edited:

Friday November 12 2021 0720 AM