TypeScript allows creating static members of a class, those that are visible on the class itself rather than on the instances.
Static members are referenced by the class name.
Static members are referenced by the class name.
TypeScript Static Properties Example
In below example, we have two static class members, one is the static property and another static method:
class Employee{
static fullName: string;
static getFullName(){
return Employee.fullName;
}
}
// create Employee class object
Employee.fullName = 'Ramesh Fadatare';
console.log(Employee.getFullName());
Output:
Ramesh Fadatare
Comments
Post a Comment