February 2018
Intermediate to advanced
298 pages
8h 22m
English
The methods that are added to the body of the class with the static prefix are called static methods. The static methods are the class' own methods; that is, they are added to the class itself rather than the prototype property of the class. For example, the String.fromCharCode() method is a static method of the string constructor, that is, fromCharCode is the property of the String function itself.
The static methods are often used to create utility functions for an application.
Here is an example to demonstrate how to define and use a static method in a class:
class Student { constructor(name) { this.name = name; } static findName(student) { return student.name; } } const s = new Student("Eden"); const name = Student.findName(s); ...Read now
Unlock full access