Classes

In ES5, "classes" are typically written as normal functions, e.g. function MyClass() {...}, with instance methods assigned to MyClass.prototype. ES2015 allows us to use the simpler class syntax.

class gives us built in instance functions, static functions, and inheritance. constructor is a special function that is called automatically every time a class instance is created. We can use the static keyword to declare static class functions. Static method calls are made directly on the class and cannot be called on instances of the class.

Inheritance

class gives us simple inheritance with the keyword extends. Classes that inherit from a parent have access to respective parent functions via super.

For full details on the class syntax, see the MDN reference for class.

Classes

In ES5, "classes" are typically written as normal functions, e.g. function MyClass() {...}, with instance methods assigned to MyClass.prototype. ES2015 allows us to use the simpler class syntax.

class gives us built in instance functions, static functions, and inheritance. constructor is a special function that is called automatically every time a class instance is created. We can use the static keyword to declare static class functions. Static method calls are made directly on the class and cannot be called on instances of the class.

Inheritance

class gives us simple inheritance with the keyword extends. Classes that inherit from a parent have access to respective parent functions via super.

For full details on the class syntax, see the MDN reference for class.