JavaScript method/Binding Unbind Event

Source: Internet
Author: User

Many JS plug-ins begin with the Code (function ( which is not quite clear until you see

 //  Event Bindings  this.bindHandler =  (function ()  {                  if  (Window.addeventlistener)  {//   Standard browser           return function (Elem, type,  handler)  {// elem: node     type: Event Type    handler: event handler                //  the last parameter is true: Call event handlers in the capture phase      false: Invoke event handlers in the bubbling phase                elem.addeventlistener (Type, handler, false);          }    } else if  (window.attachevent)  {// ie Browser          return function (elem, type ,  handler)  {   &NBSp;          elem.attachevent ("On"  + type,  Handler) (          }    }) ();         //  Event Cancellation this.removehandler =  (function ()  {                 if  ( Window.removeeventlisterner)  {//  Standard browser         return  function (Elem, type, handler)  {             elem.removeeventlisterner (Type, handler, false);         }     } else if  (window.detachevent)  {// ie Browser           return function (Elem, type, handler )  {     &NBsp;        elem.detachevent ("on"  + type, handler);           }     }) ();

Simplification into

A = (function () {return function (b) {alert (b);  } })(); A (' $b $ ');

It's clear at one glance: The return value of the call function is the closure function

JavaScript method/Binding Unbind Event

Related Article

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.