Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Questions | Answers | Discussions | Knowledge sharing | Communities & more.
The extends keyword is used in class declarations/expressions to create a class which is a child of another class. It can be used to subclass custom classes as well as built-in objects. The syntax would be as below,
class ChildClass extends ParentClass { … }
Let’s take an example of Square subclass from Polygon parent class,
class Square extends Rectangle {
constructor(length) {
super(length, length);
this.name = “Square”;
}
get area() {
return this.width * this.height;
}
set area(value) {
this.area = value;
}
}
The extends keyword is used in class declarations or expressions to create a class that acts as a subclass of another, with the parent class (sometimes called the “base class”) serving as the prototype of the child class (sometimes called the “subclass” or “derived class”).