| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Classes/extends | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2016 ..
class ChildClass extends ParentClass { ... }
extends .
extends Square Polygon. live demo (source).
class Square extends Polygon {
constructor(length) {
// ,
// length
// , width height,
// Polygon
super(length, length);
// :
// , super()
// this. ,
// .
this.name = "Square";
}
get area() {
return this.height * this.width;
}
}
extendsclass myDate extends Date {
constructor() {
super();
}
getFormattedDate() {
var months = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
];
return (
this.getDate() + "-" + months[this.getMonth()] + "-" + this.getFullYear()
);
}
}
nullclass nullExtends extends null {
constructor() {}
}
Object.getPrototypeOf(nullExtends); // Function.prototype
Object.getPrototypeOf(nullExtends.prototype); // null
new nullExtends(); //ReferenceError: this is not defined
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-class-definitions |
This page was last modified on 29 . 2026 . by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |