Are JavaScript events in JavaScript asynchronous?

In John Resig 's book "Secrets of Javascript Ninja," he makes the following statement:

Programming for the browser is no different, except that our code is not responsible for starting the event loop and dispatching events; The browser handles this for us.

Our task is to configure handlers for various events that can occur in the browser. These events are placed in the event queue (the FIFO list, more on this later) as they occur, and the browser dispatches these events, invoking any handlers that have been set for them.

Since these events occur at unpredictable times and in unpredictable order, we say that the processing of events and, therefore, the call of their control functions are asynchronous.

I find it difficult to accept the use of the asynchronous term here. Does it not mean synchological? They may also be asynchronous, but not for the reasons presented to support this statement. Thoughts?

+5
source share
5 answers

Since these events occur in unpredictable times and in unpredictable order, we say that the processing of events and, therefore, the call of their control functions are asynchronous.

This is a white lie; perhaps a little hyperbole to make a point. Nonetheless,

  • Events without a clearly defined order can occur in an unpredictable order.

    : AJAX - ?

  • .

    : setTimeout(a); setTimeout(b); - a b.

.

+2

ajax, . xhmlhttprequest.open, , onreadystatechange ( ). DOM .

, .

:

, ()

xmlhttprequest.

+1

, Resig, , , , , , - . . - JavaScript, .

0

, , . .

- , JavaScript. . , , , , . , (), , .

, () . , , . , (, HTTP-, ).

, HTTP-, JavaScript , . -, JavaScript, . , HTTP-, , , , . . HTTP- .

, , , - , , . , HTTP-, , (, ).

, , HTTP-. , . - , , .

, . JavaScript- , . , . , JavaScript. () , HTTP- , . , -, HTTP- -.

JavaScript . . , - . , . () . - , .

, , JavaScript Concurrency . , JavaScript , Promises . .

0
source

JavaScript IS is asynchronous ... it will continue to process the code, even if the method you called has not yet returned ... so yes, that's right. This is the definition of async itself: NOT synchronized ...

I get your request, though ... because of FIFO ... but I think the term used is suitable ... because it is defined exactly as they define it.

-1
source

All Articles