| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ru/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 ..
Class expression ECMAScript 2015 (ES6). function expressions, class expressions . , . JavaScript - .
var MyClass = class [className] [extends] {
//
};
Class expression class declaration (statement). class expression ("binding identifier"), class declaration. class expression , class declaration. . typeof , class expression, "function".
, class declaration, class expression .
"use strict";
var Foo = class {}; //
var Foo = class {}; //
typeof Foo; // "function"
typeof class {}; // "function"
Foo instanceof Object; // true
Foo instanceof Function; // true
class Foo {} // Throws TypeError, doesn't allow re-declaration
class expression, "Foo".
var Foo = class {
constructor() {}
bar() {
return "Hello World!";
}
};
var instance = new Foo();
instance.bar(); // "Hello World!"
Foo.name; // "Foo"
, class expression. class expression.
var Foo = class NamedFoo {
constructor() {}
whoIsThere() {
return NamedFoo.name;
}
};
var bar = new Foo();
bar.whoIsThere(); // "NamedFoo"
NamedFoo.name; // ReferenceError: NamedFoo is not defined
Foo.name; // "NamedFoo"
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-class-definitions |
This page was last modified on 27 2024 . 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 |