- 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.
- Getting Started with React
- Oracle 11g從入門到精通(第2版) (軟件開發(fā)視頻大講堂)
- 自己動(dòng)手實(shí)現(xiàn)Lua:虛擬機(jī)、編譯器和標(biāo)準(zhǔn)庫(kù)
- 深度學(xué)習(xí)經(jīng)典案例解析:基于MATLAB
- Twilio Best Practices
- 算法精粹:經(jīng)典計(jì)算機(jī)科學(xué)問(wèn)題的Java實(shí)現(xiàn)
- oreilly精品圖書:軟件開發(fā)者路線圖叢書(共8冊(cè))
- Python高級(jí)機(jī)器學(xué)習(xí)
- Mastering Google App Engine
- Nginx Lua開發(fā)實(shí)戰(zhàn)
- PLC應(yīng)用技術(shù)(三菱FX2N系列)
- C#程序設(shè)計(jì)教程(第3版)
- Mastering OAuth 2.0
- HTML5游戲開發(fā)實(shí)戰(zhàn)
- 你必須知道的.NET(第2版)