About event listeners and throwing hair

 
So far into the subject again today!
A total of two things: the first is listening and throwing hair in order to perform a function in reducing the degree of coupling, the second is why the first listening and then throw hair
 
1, the execution order of the event object function:
In the event listener function if you want to execute the sentence would write this sentence hair before throwing incident
 

 

 

 

  When writing will be executed first event after throwing hair hair throwing event, who received the hair toss event (that is to say who added the event listener) who will perform at the event here evyt throw sent out, this will flyy evt type as an argument to be brought out, and this time accepted this event in obj2.init, the function to add the listener to continue, it will first perform "I'll print" this sentence; turn back in obj2.init continue to implement a custom event evt, will fly this type as a parameter, throwing sent out, this time on the back obj1.init accepted this event, continue to function in the last sentence of the statement, print out "after I Print"

 

 

 
2, why did you add an event listener, then throw hair?
In the event of an object, because here is their definition of the event, is privately owned, throwing hair when this event has not been created out, this time on the issue related to the execution of the order, because the object method is invoked, it calls time to have the order; in the event of a normal function; also the first listening and then throw hair, although the functions are stored on the heap, but in the memory function is ordered, if the first pass in a custom event, but the event has not yet written a function at this time, it will not show results.
 
  1, event functions:
 
  This is not the result of:
  

 

  This is the right way to open:
  
 
  2, ordinary functions:
  This is not the result of

  

   

  This is the correct way to open:

  

 

Guess you like

Origin www.cnblogs.com/LiuBaoy/p/11311745.html
Recommended