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

149
Visualizações
Should I use event emitter when building library?

I'm building a library that help you to create login/register form with only JavaScript (this idea sucks, I know but I build it in order to learning more about JavaScript).

And should I use event emitter to build custom events? I mean, for example, I want to create an event occurs when the user clicks on forget password button (e.g the event name is "onForgetPassword"), or just simple like an event named "onLogin" occurs when the user submit login form. Should i create all of that with event emitter? And those event will be "emitted" when some regular DOM event is happen (for example, the custom "onLogin" event will be emitted when these is an DOM submit event is happens on the form).

Here is an example codes of the "user POV":

myLoginForm.on("onLogin", function(eventObject) {
   console.log("The user logged in!")
   console.log("The log in informations: ", eventObject)
})

/* 
myLoginForm is an object that's generated by my library, 
which contains informations about the form and some methods
which also contains the 'on' method to listen to event.
*/

// Now whenever the login form is being submitted, 2 message will log to the console.

And im not using EventEmitter class from node.js, because we don't have it in the browser, but I use this events package from npm, which bring EventEmitter to the environment that don't have it.

The reason I want to do that is because, well I think its much more convenient for the user to use these kind of custom events, so I can give them more information via the "eventObject". And also help the user to listen for more complex events (like the "onForgotPassword" event), which with regular dom event we need to writing more codes.

And by the way, in JavaScript library, is there any terms like "library for browser" or "library for server" (maybe built with Node.js)? Or is there just one type of JavaScript library? Im kinda confused, so hopefully you guys can help me to make it clear. Thank you so much!

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