Welcome! Please hold on...

0 %
Kashif Sohail
Sr. Frontend Developer
  • Residence:
    Pakistan
  • City:
    Karachi
  • Age:
    26
Magento 1x 2x
Wordpress
Laravel
Angular
React
English
Urdu
  • Bootstrap, Tailwind
  • Sass, Less, Css
  • Webpack
  • GIT knowledge
0

No products in the cart.

Callbacks On Web Components? | CSS-Tricks

September 5, 2024

[ad_1]

A jewel from Chris Ferdinandi which details how to use custom events to hook into web components. More importantly, Chris carefully explains Why Custom events are more suitable than callback functions.

With a typical JavaScript library, you pass callbacks as part of the instantiation process. […] However, since web components instantiate themselves, there is no easy way to do this.

There is a way to use callback functions, but there is no “easy” way to do it.

JavaScript provides developers with the ability to emit custom events that developers can access using the Element.addEventListener() Procedure.

We can use custom events to allow developers to intervene in the code we write and execute more code when something happens. They provide a really flexible way to extend the functionality of a library or code base.

Don’t miss the nugget about Canceling custom events!

Direct link →

[ad_2]

Source link

Posted in TechnologyTags:
Write a comment