February 2019
Beginner
694 pages
18h 4m
English
Similar to static functions, classes can also have static properties. If a property of a class is marked as static, then each instance of this class will have the same value for the property. In other words, all instances of the same class will share the static property. Consider the following code:
class StaticProperty {
static count = 0;
updateCount() {
StaticProperty.count ++;
}
}
This class definition uses the static keyword on the class property count. It has a single function named updateCount, which increments the static count property. Note the syntax within the updateCount function. Normally, we would use the this keyword to access properties of a class.
Here, however, we need to reference the full name of the ...
Read now
Unlock full access