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

139
Vistas
Using other object's method directly vs. using event

Let there be two objects: A and B.

A has a method: A.methodA(), and B also has a method: B.methodB().

Given this situation, please consider the below codes.

(1) Using other object's method directly

methodA() {
  B.methodB();
}

A.methodA(); // B.methodB invoked

(2) Using event to call other object's method

window.addEventListener('call', callcallback);

function callcallback() {
  B.methodB();
}

methodA() {
  window.dispatchEvent('call');
}

A.methodA(); // B.methodB invoked

Both ways will result in calling B.methodB(), but I wonder what is the difference. Also I would like to know which way is better. (Or does each way depend on a situation which it is used?)

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