| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Operators/class | [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 3.
class ECMAScript 2015 (ES6) . function , class (named) (unnamed) . , (body) (local). JavaScript () .
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
var MyClass = class [className] [extends] {
// class body
};
class class . , class ("binding identifier") class .
"Foo" class .
var Foo = class {
constructor() {}
bar() {
return "Hello World!";
}
};
var instance = new Foo();
instance.bar(); // "Hello World!"
Foo.name; // ""
, class . class .
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 |
This page was last modified on 2025 2 11 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 |