July 2017
Intermediate to advanced
454 pages
10h 1m
English
In TypeScript, all members in a class are public by default. We have to add the private keyword explicitly to control the visibility of the members, and this useful feature is not available in JavaScript:
class SimpleCalculator {
private x: number;
private y: number;
z: number;
constructor(x: number, y: number) {
this.x = x;
this.y = y;
}
addition() {
this.z = this.x + this.y;
}
subtraction() {
this.z = this.x - this.y;
}
}
class ComplexCalculator {
z: number;
constructor(private x: number, private y: number) { }
multiplication() {
this.z = this.x * this.y;
}
division() {
this.z = this.x / this.y;
}
}
Note that in the SimpleCalculator class, we defined x and y as private properties, which will not be visible ...
Read now
Unlock full access