In recent Typescript, it is possible to define static block
class Car {
static nextSerialNumber = 100
static {
// this is the static field
fetch('https://get-next-serial-number.com')
.then(res => res.json())
.then(data => {this.nextSerialNumber = data.mostRecentInvokedId + 1})
}
}
When the static block run?
It runs as soon as the Class definition runs. So it runs before we create a new class instances.
标签:runs,Typescript,res,static,Static,Class,block From: https://www.cnblogs.com/Answer1215/p/17967941