I have a class that only holds a static method, and there is no need to ever instantiate it. I want this class to wrap an "enum" with static values, to be used by the static method under this class. Here is a simplified example of this use case as i "wanted" it too look like:
class UserActionsService {
static actionTypes = {
foo: 1,
bar: 2,
buzz: 3
};
static doSomethingWith(actionType) {
console.log(actoinType);
}
}
and the usage should have look like:
UserActionsService.doSomethingWith(UserActionsService.actionTypes.buzz);
But, since i couldn't make the static actionTypes
member work, i wrapped it with a static function like so:
class UserActionsService {
static actionTypes() {
return {
foo: 1,
bar: 2,
buzz: 3
};
}
static doSomethingWith(actionType) {
console.log(actoinType);
}
}
And use it like this:
UserActionsService.doSomethingWith(UserActionsService.actionTypes().buzz);
///////////////////////////////////////////////// Ugly part here ^^
It works, but ugly. Am i missing something? Is there a specific reason that makes only static methods available, and not static members?