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

  • Expert Angular
  • Mathieu Nayrolles Rajesh Gunasundaram Sridhar Rao
  • 75字
  • 2021-07-15 17:05:32

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.

主站蜘蛛池模板: 普洱| 稻城县| 内乡县| 嘉鱼县| 剑河县| 青阳县| 栾城县| 汶川县| 图们市| 仲巴县| 呼和浩特市| 子洲县| 饶河县| 竹溪县| 旬邑县| 滦平县| 平阴县| 个旧市| 云梦县| 共和县| 二连浩特市| 犍为县| 精河县| 玉田县| 鄂伦春自治旗| 上林县| 德令哈市| 阿拉尔市| 祥云县| 韶关市| 大邑县| 宜都市| 勃利县| 霞浦县| 南皮县| 元谋县| 北安市| 铜川市| 水城县| 隆回县| 敖汉旗|