Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

212
Views
How can I access a dictionary in its own class/context to define a method?

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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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]()

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!