Professional Documents
Culture Documents
ES 6 Class and Inheritance
ES 6 Class and Inheritance
class Mobile { }
Parent Parent
Child Child
GrandChild
Class Inheritance
The extends keyword is used in class declarations or class
expressions to create a class which is a child of another class.
The extends keyword can be used to subclass custom classes as
well as built-in objects.
class Father {
}
Father
Son
class Son extends Father {
}
Class Inheritance
• Inherit Built-in Object
– Date
– String
– Array
}
Super
Super ( ) is used to initialize parent class constructor. If there is a constructor present in subclass, it
needs to first call super() before using "this". A constructor can use the super keyword to call the
constructor of a parent class.
Class Father {
constructor (money) {
this.Fmoney = money;
}
}
Class Son extends Father {
constructor (money){
super(money);
}
}
var s = new Son(10000);
Method Overriding
Same function name with different implementation.
Child show
show(()){return
{return“Sub Class”;
“Super } }
Class”;
Static Method
The static keyword is used to define a static method for a class. Static methods
are called without creating object and cannot be called through a class instance
(object). Static methods are often used to create utility functions for an
application.
Ex:-
class Mobile {
constructor ( ) { }
static disp ( ) { return “Static Method”; }
}
Mobile.disp( ) ;