AddEventListener Event Function Transfer "reprint"

Source: Internet
Author: User

The AddEventListener parameters are as follows:

AddEventListener (Type, listener[, Usecapture]);
    1. Type, event name
    2. Listener, event handler
    3. 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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.