New features are added to ECMAScript language by TC39 team. Here is the probable list of features that are expected in ES2022 or ES13.
Class Static Initialization Blocks
Class static
blocks perform additional static initialization during class definition evaluation. Currently, this feature is in Stage 3.
Right now, we can declare static variables and methods inside a class. Example:
class A {
static fruit = "Apple";
static dish = "";
static show() {
return "I ate Apple";
}
}
Later, if we need to do an evaluation on this static properties, we need to do it outside the class definition.
try {
const obj = whatToCook(A.fruit);
A.dish = obj.dish;
} catch {
A.dish = "Pie";
}
Using static
blocks, we can now move this code inside class A
.
class A {
static fruit = "Apple";
static dish = "";
static show() {
return "I ate Apple";
}
static {
try {
const obj = whatToCook(A.fruit);
A.dish = obj.dish;
} catch {
A.dish = "Pie";
}
}
}