- 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.
- Advanced Quantitative Finance with C++
- 深度學(xué)習(xí)經(jīng)典案例解析:基于MATLAB
- Apache Hive Essentials
- Scala編程實(shí)戰(zhàn)(原書第2版)
- ASP.NET程序設(shè)計(jì)教程
- Python數(shù)據(jù)結(jié)構(gòu)與算法(視頻教學(xué)版)
- Nginx Lua開發(fā)實(shí)戰(zhàn)
- D3.js By Example
- R用戶Python學(xué)習(xí)指南:數(shù)據(jù)科學(xué)方法
- Python程序設(shè)計(jì)與算法基礎(chǔ)教程(第2版)(微課版)
- Hands-On Nuxt.js Web Development
- C++編程兵書
- C語(yǔ)言程序設(shè)計(jì)實(shí)訓(xùn)教程與水平考試指導(dǎo)
- Visual Basic 程序設(shè)計(jì)實(shí)踐教程
- 微服務(wù)設(shè)計(jì)