Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

120
Visualizações
Structuring Javascript classes for interoperation

So like wading into a beach pool and finding it has a riptide, my journey in JS programming has gotten complicated quite quickly.

I have an application I am building that has a class, cataloque.js that loads and renders data. It currently does a few things that I would rather it didn't such as put up dialogs for the user.

It is imported into a file, core.js, that handles my user interaction and building parts of the UI

I want to take those user alert functions and put them into another class but then I run into some problems. A class can't be a module (as the this. operator is set to window. in modules) so I can't import another class into catalogue.js.

I also can't seem to reference functions in the core.js file from my class.

So what is the best way to structure this so I can import multiple classes and still have some way of having them 'talk' to the core.js functions?

To help illustrate:

core.js

  • imports catalogue.js creates new class variable
  • imports dialogs.js creates new class variable

So if I have code in the cataloque class that needs to alert the user and I want to call code in the dialog class how do I mediate that communication?

So catalogue calls core which then calls dialog to show the user a dialog

Do I need to declare a namespace in core.js? Is this just a crazy way to build something in JS?

Also, I have done a lot of searches for articles in this vein but I assume that since the class structure has undergone changes recently that there are not a lot of references available via searches so any good reading suggestions would be quite helpful.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda