CLASSES
The previous sections are an in-depth overview of how it was possible to emulate class-like behavior using only features available in ECMAScript 5. It is not difficult to conclude that the strategies shown presented various problems and tradeoffs. On top of this, the syntax was inarguably excessively verbose and messy.
To address these problems, newly introduced in ECMAScript 6 is the ability to formally define classes using the class
keyword. Classes are a fundamentally new syntactical construct in ECMAScript, and therefore they may feel unfamiliar at first. Although ECMAScript 6 classes appear to feature canonical object-oriented programming, they still uses prototype and constructor concepts under the hood.
Class Definition Basics
Similar to the function type, there are two primary ways of defining a class: class declarations and class expressions. Both use the class
keyword and curly braces:
// class declaration
class Person {}
// class expression
const Animal = class...