![]() |
VOOZH | about |
There are three concepts in Object-Oriented Programming Object, Class, and Methods. ES6 JavaScript supports Object-Oriented programming components.
The class contains the Constructors and Functions. The Constructors take responsibility for allocating memory for the objects of the class. The function takes responsibility of the action of the objects. Combing these two Constructor and Functions to make the Class.
In the ES6 to create any class, you need to use the class keyword.
Syntax: Declaring Class:
class Class_name {
}
Class Expressions:
var var_name = new Class_name {
}
The below example will illustrate the ES6 Classes:
Example: This example shows the use of ES6 classes.
Class inheritance: The ES6 Class supports the inheritance. Inheritance has the courage to create entities from existing entities. There are two types of Class in ES6:
Syntax:
class child_name extends parent_nameExample: This example shows the inheritance in classes.
Inheritance divided into three types:
class Child extends Root
class Leaf extends Child
// So the leaf extends root indirectly
Super Keyword: This keyword helps child class to invoke the parent class data.
super.objectExample: This example shows the use of the super keyword in ES6.
Output:
This doPrint() from Parent called.
This doPrint() is printing a string.