- 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.
- 多媒體CAI課件設計與制作導論(第二版)
- 零基礎學C++程序設計
- 兩周自制腳本語言
- SQL for Data Analytics
- Python Geospatial Development(Second Edition)
- 薛定宇教授大講堂(卷Ⅳ):MATLAB最優(yōu)化計算
- 老“碼”識途
- Python機器學習實戰(zhàn)
- Android 應用案例開發(fā)大全(第3版)
- Mastering Apache Spark 2.x(Second Edition)
- 小程序,巧應用:微信小程序開發(fā)實戰(zhàn)(第2版)
- PHP 7從零基礎到項目實戰(zhàn)
- C語言程序設計與應用(第2版)
- Java7程序設計入門經(jīng)典
- NGUI for Unity