[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/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 3.

class , .

In this article

class Polygon {
  constructor(height, width) {
    this.area = height * width;
  }
}

console.log(new Polygon(4, 3).area);
// Expected output: 12

. .

js
    class name [extends] {
      // class body
    }

. ..

.

Polygon , Square Polygon . 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";
  }
}

: .

js
class Foo {}
class Foo {} // Uncaught SyntaxError: Identifier 'Foo' has already been declared

.

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