Back to Content

Static method

files/en-us/glossary/static_method/index.md

latest1.2 KB
Original Source

A static method (or static function) is a {{Glossary("method")}} defined as a member of an {{Glossary("object")}} but is accessible directly from an API object's constructor, rather than from an object instance created via the constructor.

In a Web API, a static method is one which is defined by an interface but can be called without instantiating an object of that type first.

Methods called on object instances are called instance methods.

Examples

In the Notifications API, the {{domxref("Notification/requestPermission_static", "Notification.requestPermission()")}} method is called on the actual {{domxref("Notification")}} constructor itself — it is a static method:

js
let promise = Notification.requestPermission();

The {{domxref("Notification.close()")}} method on the other hand, is an instance method — it is called on a specific notification object instance to close the system notification it represents:

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

myNotification.close();

See also

  • static
  • Related glossary terms:
    • {{Glossary("Object")}}
    • {{Glossary("Method")}}