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 method)

정적 메서드 (또는 정적 함수)는 객체의 멤버로 정의된 메서드이지만 생성자를 통해 생성된 객체 인스턴스가 아닌 API 객체의 생성자에서 직접 접근할 수 있습니다.

Web API에서, 정적 메서드는 인터페이스에 의해 정의되지만 해당 유형의 객체를 먼저 인스턴스화하지 않고도 호출할 수 있는 메서드입니다.

객체 인스턴스에서 호출되는 메서드를 '인스턴스 메서드'라고 합니다.

예제

Notifications API에서, Notification.requestPermission() 메서드는 Notification 생성자 자체에서 호출됩니다. Notification.requestPermission() 메서드는 정적 메서드입니다.

js
let promise = Notification.requestPermission();

반면에 Notification.close() 메서드는 인스턴스 메서드입니다. 이는 특정 알림 객체 인스턴스에서 호출되어 해당 시스템 알림을 닫습니다.

js
let myNotification = new Notification("This is my notification");

myNotification.close();

같이 보기