ES6 (ECMAScript 2015) Class Usage

There are some new features in ES6(ECMAScript 2015) like the following. But, we will focus on classes.

  • JavaScript let
  • JavaScript const
  • JavaScript Arrow Functions
  • JavaScript Classes
  • Default parameter values
  • Array.find()
  • Array.findIndex()

Class Declaration Syntax

Instance properties must be defined inside of class methods.

Class Expression

class expression is another way to define a class.

Getter/Setter

The name of the getter/setter method cannot be the same as the name of the property.

Class with constructor and getter/setter

Private fields and functions are not support in ES6 yet. So, you can reach any fields declared in constructor like _firstName;

Computed Method Names

Inheritance(Sub classing with extends) and Overriding methods(Polymorphism)

Inheritance can be achieved with function declaration or function expression in ES5. So you should read the following posts as well.

draw() method is overrided. There is no keywords like virtual, override etc.

Mix-ins style multiple inheritance

Another example.

Another example.

Static Methods

Another example.

Leave a Reply