官术网_书友最值得收藏!

Static properties

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.

主站蜘蛛池模板: 禄丰县| 同仁县| 清远市| 江陵县| 敦化市| 彩票| 会泽县| 安仁县| 太谷县| 台北市| 双峰县| 阜平县| 布拖县| 泰顺县| 太白县| 双城市| 米脂县| 富裕县| 偃师市| 达尔| 七台河市| 罗定市| 海晏县| 鄂托克前旗| 潞西市| 磴口县| 东至县| 恩平市| 九江县| 盘锦市| 海安县| 宜良县| 红原县| 玉林市| 襄城县| 大埔县| 长宁县| 岳阳市| 讷河市| 泾阳县| 阳山县|