Internal javascript: how are events implemented?

My question is related to how JS mechanisms implement an asynchronous event pattern when we do something like dom binding event handlers to resolve the click event.

Do they have something like a separate thread that listens for all click events? When an event occurs, do they reference a list of bindings and trigger events?

Similarly with Ajax, an asynchronous network call, where the browser spans a new thread that starts listening on data from the server and when it receives a response, will it call a success handler?

+6
source share
1 answer

Read this post about the javascript event queue and see if it answers most of your questions. There will be a native OS thread that handles the interaction with real OS events (mouse events, keyboard events, timer events, network I / O events, etc.), and then they are sent to the JS queue, where the JS mechanism can send them to javascript code. How many separate threads at the OS level has implementation specificity and probably depends on the implementation.

+7
source

Source: https://habr.com/ru/post/900559/


All Articles