Home > Web Front-end > JS Tutorial > body text

JavaScript running mechanism events and callback functions

php中世界最好的语言
Release: 2018-03-16 15:29:00
Original
2353 people have browsed it

This time I will bring you JavaScript events and callback functions of the running mechanism, Notes on using JavaScriptrunning mechanismare Which ones, the following are practical cases, let’s take a look.

"TaskQueue" is an event queue (can also be understood as a message queue). When the IO device completes a task, it adds an event to the "task queue", which means Related asynchronous tasks can enter the "execution stack". The main thread reads the "task queue", which means reading the events in it.

The events in the "Task Queue", in addition to IO device events, also include some user-generated events (such as mouse clicks, page scrolling, etc.). As long as the callback function is specified, these events will enter the "task queue" when they occur, waiting for the main thread to read.

The so-called "callback function" (callback) is the code that will be hung up by the main thread. Asynchronous tasks must specify a callback function. When the main thread starts executing an asynchronous task, the corresponding callback function is executed.

"Task queue" is a first-in, first-out data structure. The events ranked first are read by the main thread first. The reading process of the main thread is basically automatic. As soon as the execution stack is cleared, the first event on the "task queue" will automatically enter the main thread. However, due to the "Timer" function mentioned later, the main thread must first check the execution time. Certain events can only return to the main thread after the specified time.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Why JavaScript is single-threaded in JavaScript running mechanism

Task queue in JavaScript running mechanism

The above is the detailed content of JavaScript running mechanism events and callback functions. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!