JQuery.event.dispatch, literally means event distribution. Is the function that executes the binding.
In the JQuery.event.add,
// 1, in JQuery.event.add jQuery.event.dispatch.apply (Eventhandle.elem, arguments) // 2, JQuery.event.simulate in jQuery.event.dispatch.call (Elem, E);
Let's take a look at the source code of JQuery.event.dispatch and see what it achieves.
Dispatchfunction(event) {//Fix Event Source Objectevent =JQuery.event.fix (event); varI, J, ret, matched, handleobj, Handlerqueue=[], args=Core_slice.call (arguments),//gets the bound event objectHandlers = (Data_priv.get ( This, "events") | | {}) [Event.type] | |[], special= jquery.event.special[Event.type] | | {}; args[0] =event; Event.delegatetarget= This; //Call the Predispatch hooks for the mapped type, and let it bail if desired if(Special.predispatch && Special.preDispatch.call ( This, event) = = =false ) { return; } //get the execution queue for handlerHandlerqueue = JQuery.event.handlers.call ( This, event, handlers); //Run delegates first; they may want to stop propagation beneath USi = 0; while((matched = handlerqueue[i++]) &&!event.ispropagationstopped ()) {Event.currenttarget=Matched.elem; J= 0; while((Handleobj = matched.handlers[j + +]) &&!event.isimmediatepropagationstopped ()) { //there is no namespace, or a matching namespace if(!event.namespace_re | |event.namespace_re.test (Handleobj.namespace)) {Event.handleobj=Handleobj; Event.data=Handleobj.data; //executing a binding functionret = ((jquery.event.special[Handleobj.origtype] | | {}). Handle | |handleobj.handler). Apply (Matched.elem, args); //if it is return FALSE, block the default event and prevent bubbling if(Ret!==undefined) { if((Event.result = ret) = = =false) {event.preventdefault (); Event.stoppropagation (); } } } } } //Call the Postdispatch hooks for the mapped type if(Special.postdispatch) {Special.postDispatch.call ( This, event); } returnEvent.result;},
JavaScript event: JQuery.event.dispatch detailed