| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Classes/static | [Back] [Original] |
Get to know MDN better
This feature is well established and works across many devices and browser versions. Its been available across browsers since 20163.
static methodclassinstanceutility functions
static methodName() { ... }
(instantiating)(instantiating) (utility functions)
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 |
This page was last modified on 2025716 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 |