[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Classes/extends [Back]  [Original]

extends - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

extends

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2016 ..

extends .

In this article

class ChildClass extends ParentClass { ... }

extends .

.prototype Object null.

extends

Square Polygon. live demo (source).

js
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;
  }
}

extends

Date. live demo (source).

js
class 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()
    );
  }
}

null

null , , Object.

js
class 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


Web Proxy Viewer  |  New URL  |  Original Page