Event is asynchronous or synchronous?

Beginner front of the time, saying the data is asynchronous events.
The description also mdn asynchronous.

Event (Event) refers to the design pattern for asynchronous calls deal with various events of the page life cycle, but also refers to the name, description and use of a number of different types of events.

At that time I do not care, will be used on the line.


Later, he met HTMLElement.click

var dom = document.querySelector('xxx')
dom.addEventListener('click',function(){ console.log(' dom is clicked ') })

function test (){
    dom.click()
    console.log(' after dom.click() ')
}
test() // 'dom is clicked'  ' after dom.click() '

Manually trigger the event which triggers the function is not executed asynchronously.

So at that time that the event is synchronized.


There ajax xhr of readyStateChange such events bothered me for a long time.

Events are still unclear asynchronous or synchronous. Check the information, I did not understand.


I think that the event is a process:

  1. Trigger behavior (asynchronous)
  2. Event Processing (synchronous)

He says such a pass.

Behavior Trigger: When the user clicks, returns a response, it is unknown which is asynchronous.

Event processing: The system receives an event trigger, find the corresponding dom callback function, process and execution is synchronous.

dom.click () directly triggered so immediately.

Guess you like

Origin www.cnblogs.com/AFu-1993/p/12319673.html