I want to create code like this:
<code>class foo {
static [x % 2 == 0]() {
return x / 2;
}
static [x % 2 == 1]() {
return x * 3 + 1;
}
}
</code>
<code>class foo {
static [x % 2 == 0]() {
return x / 2;
}
static [x % 2 == 1]() {
return x * 3 + 1;
}
}
</code>
class foo {
static [x % 2 == 0]() {
return x / 2;
}
static [x % 2 == 1]() {
return x * 3 + 1;
}
}
I tried many ways but it didn’t work.
Is it possible to get the key value used to access a field in JavaScript?
Or is it possible to give default values to undefined fields?
New contributor
user26791903 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1