Static and Accessors
static belongs to the class. get and set make accessors.
Example
class C {
static count = 0;
private _v = 1;
get v() { return this._v; }
set v(n: number) { this._v = n; C.count++; }
}
const c = new C(); c.v = 5;
console.log(c.v, C.count);Result
5 1
Exercise
Class property.
count = 0Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.