[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Classes/static [Back]  [Original]

static - 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

static

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2016 ..

, , static.

In this article

static methodName() { ... }

. . .

, this.

js
class StaticMethodCall {
  static staticMethod() {
    return "  ";
  }
  static anotherStaticMethod() {
    return this.staticMethod() + "    ";
  }
}
StaticMethodCall.staticMethod();
// '  '

StaticMethodCall.anotherStaticMethod();
// '      '

, this . : CLASSNAME.STATIC_METHOD_NAME() : this.constructor.STATIC_METHOD_NAME().

js
class StaticMethodCall {
  constructor() {
    console.log(StaticMethodCall.staticMethod());
    // '  .'

    console.log(this.constructor.staticMethod());
    // '  .'
  }

  static staticMethod() {
    return "  .";
  }
}

:

  1. .
  2. .
  3. .
js
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


Web Proxy Viewer  |  New URL  |  Original Page