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

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

class

Baseline Widely available

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

Class declaration .

, class expression. class expression, class declaration , .

In this article

js
class name [extends] {
  //  
}

class expression, class declaration . .

Class declaration ( ).

class declaration

Polygon, Square. , super(), , , this.

js
class Polygon {
  constructor(height, width) {
    this.name = "Polygon";
    this.height = height;
    this.width = width;
  }
}

class Square extends Polygon {
  constructor(length) {
    super(length, length);
    this.name = "Square";
  }
}

: class declaration . js class Foo {}; class Foo {}; // Uncaught TypeError: Identifier 'Foo' has already been declared , class declaration.

js
var Foo = class {};
class Foo {} // Uncaught TypeError: Identifier 'Foo' has already been declared

Specification
ECMAScript 2027 LanguageSpecification
# sec-class-definitions


Web Proxy Viewer  |  New URL  |  Original Page