Reputation: 2657
Is something like this possible?
const propName = "x";
class A {
static propName = 1
// equivalent to static x = 1
}
A[propName] // evaluates to 1
or would it be (typeof A)[propName]
?
For obvious reasons, this is not a duplicate of this question
Upvotes: 1
Views: 58
Reputation: 2657
This is possible, simply as:
const propName = "x";
class A {
static [propName] = 1
// equivalent to static x = 1
}
A[propName]
Upvotes: 2