Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

222
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda