A toned-down example is this class, inheriting from PublishableAction (to provide the static .viewController() function as well as other methods which is used where the // ... is):
class Action extends PublishableAction {
static actionSelector = {
buttonCommit: Symbol()
};
// This part still works as intended, accessing 'Action':
static buttonSession = Action.viewController({
perform: Action.actionSelector.buttonCommit
});
// ... but here's the issue:
// ReferenceError: Cannot access 'Action' before initialization
[Action.actionSelector.buttomCommit]() {
// ...
}
}
I have already tried using [this.actionSelector.buttonCommit]() and [this.constructor.actionSelector.buttonCommit](), both not having any effect on the outcome.
How can I fix the ReferenceError without having to move Action.actionSelector to the global scope?
It's a bit of a weird pattern what you are trying to achieve. But maybe have a "methods" getter and return there every callable method that rely on actionSelector?
class Action extends PublishableAction {
static actionSelector = {
buttonCommit: Symbol()
};
// This part still works as intended, accessing 'Action':
static buttonSession = Action.viewController({
perform: Action.actionSelector.buttonCommit
});
get methods() {
return {
[Action.actionSelector.buttonCommit]: function() {
//...
}
};
}
}
Than you can call (new Action()).methods[Action.actionSelector.buttonCommit]()