The name
property of a JavaScript class constructor is read-only once the class is defined, but it can be modified by a static field definition in the class body itself. However, I was surprised to find that it can’t be modified in a static initialization block.
This works great:
class Foo {
static name = 'Bar';
}
But this throws a TypeError saying that name
is read-only:
class Foo {
static {
this.name = 'Bar';
}
}
Is this the intended behavior or an accidental quirk in the spec?