- 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.
推薦閱讀
- Spring Boot 2實戰之旅
- C++面向對象程序設計(微課版)
- C# 從入門到項目實踐(超值版)
- Elastic Stack應用寶典
- Mastering Ubuntu Server
- 微信小程序開發解析
- Python數據可視化之Matplotlib與Pyecharts實戰
- Integrating Facebook iOS SDK with Your Application
- SQL基礎教程(第2版)
- Go語言編程
- OpenCV 3.0 Computer Vision with Java
- Java EE輕量級解決方案:S2SH
- 微服務設計
- Python Business Intelligence Cookbook
- Visual FoxPro程序設計