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

static - JavaScript | MDN

MDN Web Docs

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 20163.

static methodclassinstanceutility functions

In this article

static methodName() { ... }

(instantiating)(instantiating) (utility functions)

js
class Triple {
  static triple(n) {
    n = n || 1; //should not be a bitwise operation
    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
console.log(BiggerTriple.triple(3)); // 81
var tp = new Triple();
console.log(tp.triple()); // 'tp.triple is not a function'.

Specification
ECMAScript 2027 LanguageSpecification
# sec-class-definitions


Web Proxy Viewer  |  New URL  |  Original Page