- Learning Ionic(Second Edition)
- Arvind Ravulavaru
- 180字
- 2021-07-02 23:24:24
Classes
I am a guy who believes that JavaScript is an object-based programming language and not an object-oriented programming language, and I know quite a lot of people who disagree with me.
In vanilla JavaScript, we have functions, which act like a class and exhibit prototype-based inheritance. In TypeScript/ES6, we have the class construct:
class Person {
name: string;
constructor(personName: string) {
this.name = personName;
}
getName {
return "The Name: " + this.greeting;
}
}
// somewhere else
arvind:Person = new Person('Arvind');
In the preceding example, we have defined a class named Person and we are defining the class constructor, which accepts the name on initialization of the class.
To initialize the class, we will invoke the class with a new keyword and pass in the name to the constructor. The variable that stores the instance of the class -- the object, arvind in the preceding example, can also be typed to the class. This helps in better understanding the possibilities of the arvind object.
Note: The classes in ES6 still follow Prototypal-based Inheritance and not the classical Inheritance model.
- JavaScript前端開發(fā)模塊化教程
- Learn to Create WordPress Themes by Building 5 Projects
- Python進階編程:編寫更高效、優(yōu)雅的Python代碼
- 實戰(zhàn)低代碼
- Data Analysis with IBM SPSS Statistics
- Mastering Yii
- 匯編語言程序設計(第3版)
- Java項目實戰(zhàn)精編
- Mastering Drupal 8 Views
- UI設計全書(全彩)
- JavaScript程序設計:基礎·PHP·XML
- Simulation for Data Science with R
- 視窗軟件設計和開發(fā)自動化:可視化D++語言
- Responsive Web Design with jQuery
- 深度學習:基于Python語言和TensorFlow平臺(視頻講解版)