The AddEventListener parameters are as follows:
AddEventListener (Type, listener[, Usecapture]);
- Type, event name
- Listener, event handler
- Usecapture, whether to capture
Always remember that listener is a response function, type of functions. I believe a lot of people understand that too. Most of the time this is used
function (EV) { // todofalse);
The first parameter has no objection, the second parameter passes a function, the third argument passes false, and the event stream is consistent with the low version ie (both bubbles).
Read Iscroll.js (5.1.3) source code found that there is such a way of writing
// _initevents 863 lines, method This this//EventType 42 line, function (EL, type, FN, capture) { !! capture);};
Simplified to the following test generation
var function (EV) { console.log (EV)}}document.addeventlistener (false)
Yes, the second parameter is not a function, but an object. A bit confused, the world view 1:30 will not change over. How could it be an object? The consequences of inertia thinking and not looking at norms are immense. Click the document without an error stating that it is really possible to use this.
The actual DOM2 of listener, defined in Events, does not say that it must be a function type.
Interface EventListener (introduced in DOM level 2)
As long as the implementation of the above interface can be used as listener, simply said to add Handleevent method to the object can be used as listener.
One of the benefits of adding events in this way is that this can be easily bound to the current class when you are using class-based development. As follows
functionComponent (elem, option) { This. Elem =Elem This. handleevent =function(EV) {if(Ev.type = = = ' click ') { This. Updatenav ()}if(Ev.type = = = ' DblClick ')) { This. Updatebottom ()}} This. Init ()} Component.prototype={init:function() { This. Elem.addeventlistener (' click ', This,false) This. Elem.addeventlistener (' DblClick ', This,false)}, Updatenav:function() {Console.log (' Nav update ')}, Updatebottom:function() {Console.log (' Bottom Update ') }}
Reproduced: Original: http://www.cnblogs.com/snandy/p/4877069.html
AddEventListener Event Function Transfer "reprint"