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

143
Vistas
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 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