July 2017
Intermediate to advanced
454 pages
10h 1m
English
These properties are not instance-specific and are accessed by a class name instead of using the this keyword:
class Customer {
static bonusPercentage = 20;
constructor(public salary: number) { }
calculateBonus() {
return this.salary * Customer.bonusPercentage/100;
}
}
var customer = new Customer(10000);
var bonus = customer.calculateBonus();
Here, we declared a static variable called bonusPercentage that is accessed using the class name Customer in the calculateBonus method. This bonusPercentage property is not instance-specific.
Read now
Unlock full access