简体   繁体   中英

How Javascript event-driven works inside

If we want a callback while the user clicks a button, we just simply type
btn.addEventListener('click', callback)

The question I want to figure out is this: how can it work? How to do that?

Did the browser add a thread that continued checking for it (that's obviously not the case, since it consumes lots of resources).

Or did the browser inside use some kind of server push-technology or something else?

To simplify the description, let's just say the browser has a general "mouse click event" on it's whole application canvas, then figures out which element on the screen is at that position and fires the appropriate click event for that element.

Here's an article about WebKit internals that goes more in details on how browsers parse, DOM, events, etc...

Is that what you are looking for? What exactly are you trying to accomplish?

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM