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

class ECMAScript 2015 (ES6) . function , class (named) (unnamed) . , (body) (local). JavaScript () .

In this article

const Rectangle = class {
  constructor(height, width) {
    this.height = height;
    this.width = width;
  }
  area() {
    return this.height * this.width;
  }
};

console.log(new Rectangle(5, 8).area());
// Expected output: 40

js
    var MyClass = class [className] [extends] {
      // class body
    };

class class . , class ("binding identifier") class .

class , class .

class

"Foo" class .

js
var Foo = class {
  constructor() {}
  bar() {
    return "Hello World!";
  }
};

var instance = new Foo();
instance.bar(); // "Hello World!"
Foo.name; // ""

Named class

, class . class .

js
var Foo = class NamedFoo {
  constructor() {}
  whoIsThere() {
    return NamedFoo.name;
  }
};
var bar = new Foo();
bar.whoIsThere(); // "NamedFoo"
NamedFoo.name; // ReferenceError: NamedFoo  
Foo.name; // "NamedFoo"

Specification
ECMAScript 2027 LanguageSpecification
# sec-class-definitions


Web Proxy Viewer  |  New URL  |  Original Page