April 2018
Beginner
536 pages
13h 21m
English
In TypeScript, we can declare a function using a function expression or an arrow function. An arrow function has a shorter syntax than a function expression, and lexically binds the value of the this operator.
The this operator behaves a little differently in TypeScript and JavaScript compared to other popular programming languages. When we define a class in TypeScript, we can use the this operator to refer to the class. Let's look at an example:
class Person {
private _name: string;
constructor(name: string) {
this._name = name;
}
public greet() {
console.log(`Hi! My name is ${this._name}`);
}
}
let person = new Person("Remo");
person.greet(); // "Hi! My name is Remo"
We have defined a Person class that contains a property ...