static은 Class에 있는 정적 메서드를 선언할 때 사용한다. 정적 메서드는 클래스의 인스턴스 없이 호출이 가능하며 클래스가 인스턴스화되면 호출할 수 없다.
class StaticMethodCall {
static staticMethod() {
return 'Static method has been called';
}
static anotherStaticMethod() {
return this.staticMethod() + ' from another static method';
// 동일한 클래스 내의 다른 정적 메서드 내에서 정적 메서드를
// 호출하는 경우 키워드 this를 사용할 수 있다.
}
}
StaticMethodCall.staticMethod();
// StaticMethodCall의 인스턴스를 선언하지 않고 바로 staticMethod() 사용 가능
StaticMethodCall.anotherStaticMethod();
// StaticMethodCall의 인스턴스를 선언하지 않고 바로 anotherStaticMethod() 사용 가능