The Wayback Machine - https://web.archive.org/web/20150905231453/https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Classes/static

static

공헌자 숫자: 3명
아직 자원 봉사자들이 한국어로 현재 문서를 번역하지 않았습니다. 가입해서 이 문서가 번역되는 일에 함께 해 주세요!

This is a new technology, part of the ECMAScript 2015 (ES6) standard .
This technology's specification has been finalized, but check the compatibility table for usage and implementation status in various browsers.

The static keyword defines a static method for a class.

Syntax

static methodName() { ... }

Description

Static methods are called without instantiating their class and are also not callable when the class is instantiated. Static methods are often used to create utility functions for an application.

Examples

The following example demonstrates several things. It shows how a static method is implemented on a class and that a class with a static member can be subclassed. Finally it shows that how a static method can and cannot be called.

class Tripple {
  static tripple(n) {
    n = n | 1;
    return n * 3;
  }
}

class BiggerTripple extends Tripple {
  static tripple(n) {
    return super.tripple(n) * super.tripple(n);
  }
}

console.log(Tripple.tripple());
console.log(Tripple.tripple(6));
console.log(BiggerTripple.tripple(3));
var tp = new Tripple();
console.log(tp.tripple()); //Logs 'tp.tripple is not a function'.

Specifications

Specification Status Comment
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Class definitions' in that specification.
Standard Initial definition.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 42.0 Nightly build ? ? ?
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support Not supported Nightly build ? ? ? 42.0

See also

문서 태그 및 공헌자

Contributors to this page: fscholz, jpmedley, samhagman
최종 변경: fscholz,
사이드바 숨기기
HTTPS · web.archive.org
← Home