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

177
Visualizações
Trigger method via JS class or via jQuery trigger()?

I have a CartHandler Javascript class that contains a method named onAddToCart for communication between the page and the cart API.

Part of the class is also a method named updateCartDOM for updating DOM content upon response from cart API.

var CartHandler = function() {
  $(document.body)
    .on('click', 'form[name="addToCart"]', { CartHandler: this }, this.onAddToCart)
    .on('update_cart_dom', { CartHandler: this }, this.updateCartDOM);
};

CartHandler.prototype.onAddToCart = function(e) { /* ... */ };
CartHandler.prototype.updateCartDOM = function(e, cart) { /* ... */ };

There are two ways of triggering updating method:

  1. Triggering a jQuery event: $(document.body).trigger('update_cart_dom', [...]);
  2. Calling the update method directly since the class is the same: e.data.CartHandler.updateCartDOM(...);

What is the preferred way of triggering updating function? Does it make any difference regarding performance or security?

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