February 2019
Beginner
694 pages
18h 4m
English
A class is the definition of an object, and as such, includes the data that it can hold, in the form of class properties. These properties can be accessed by users of this class, if we so wish, or can be marked as not accessible. Regardless of what their accessibility rules are, code within the class will need to access these class properties. In order to access the properties of a class from within the class itself, we need to use the this keyword. As an example, let's update our SimpleClass definition, and print out the value of the id property within the print function, as follows:
class SimpleClass {
id: number | undefined;
print() : void {
console.log(`SimpleClass has id : ${this.id}`);
}
}
Here, we have modified the ...
Read now
Unlock full access