I want to define a static variable called index in my function, which does such as index++. that means that if this method is called, the varaible will be added.
We can use static variables in Typescript.
class Test {
static index = 1;
static print() {
console.log(Test.index++);
}
}
Test.print(); // prints 1
Test.print(); // prints 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With