| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Classes/static | [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 ..
, , static.
static methodName() { ... }
. . .
, this.
class StaticMethodCall {
static staticMethod() {
return " ";
}
static anotherStaticMethod() {
return this.staticMethod() + " ";
}
}
StaticMethodCall.staticMethod();
// ' '
StaticMethodCall.anotherStaticMethod();
// ' '
, this . : CLASSNAME.STATIC_METHOD_NAME() : this.constructor.STATIC_METHOD_NAME().
class StaticMethodCall {
constructor() {
console.log(StaticMethodCall.staticMethod());
// ' .'
console.log(this.constructor.staticMethod());
// ' .'
}
static staticMethod() {
return " .";
}
}
:
class Triple {
static triple(n) {
if (n === undefined) {
n = 1;
}
return n * 3;
}
}
class BiggerTriple extends Triple {
static triple(n) {
return super.triple(n) * super.triple(n);
}
}
console.log(Triple.triple()); // 3
console.log(Triple.triple(6)); // 18
var tp = new Triple();
console.log(BiggerTriple.triple(3));
// 81 ( )
console.log(tp.triple());
// , "tripple"
// ('tp.tripple is not a function').
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-class-definitions |
This page was last modified on 6 . 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 |