How to understand the concepts of "event handle" and "event source" in JS?

in JS development, we often hear the words "event handle" and "event source", but we don"t know much about their exact meaning. I hope God can click

.
Mar.17,2021

Don't say much about the concept, just search it on the Internet. Let me give you a chestnut.

for example, in a company, the front desk is Uncle Wang at the door, and there is a clerk Xiao Zhang in the company.
one day Xiao Zhang was going out to run errands, and he happened to have a delivery to collect, so he kindly said to Uncle Wang, "Uncle, I'm going out to do something. Come and collect it for me."

at this point, it can be said that he has registered an event handle (handle) for "receiving express delivery" with Uncle Wang (DOM object) at the front desk.

after the express delivery came, the courier looked for Xiao Zhang, so Uncle Wang said to him, "Xiao Zhang is out. I'll collect it for him." So the courier handed it over to Uncle Wang and bounced off.

then you can find that this is actually a proxy event. The Event.target under the event source, that is, the first parameter of the event handle (Event object / event object), is actually Xiao Zhang, but he has hosted this event to the uncle, so the uncle is actually Event.currentTarget that triggered the event.

of course, if Xiao Zhang chooses to receive express delivery himself, this is not an agency event. Event.target and Event.currentTarget are both Xiao Zhang himself.

< hr >

I don't know if you understand.


The

event handle refers to the action to be taken when the event occurs.
(also known as event handling function), each event corresponds to an event handle. When the program is executed, the corresponding function or statement is assigned to the event handle, and when the event occurs, the browser executes the specified function or statement, thus realizing the interaction between the web page content and the user's operation. When the browser detects that an event occurs, it looks for whether the event handle corresponding to the event has been assigned, and if so, executes the event handle.
https://baike.baidu.com/item/.

event source:

in an event, the element of the current operation is the event source. For example, both the a tag and input in the web page element have onclick events. When an onclick event occurs, the event source is the a tag. When you click input to send the onclic event, the event source is input.

https://blog.csdn.net/u014205.

The

handle is translated, so it is easier for you to read it directly in English. It is also difficult for me to understand the word handle at first

Menu