How does the jQuery .unbind() function work in JavaScript? -


some background: javascript function .removeeventlistener() requires explicit declaration of handler want remove, while jquery's .unbind() automatically remove event listeners associated given element.

taking @ jquery source code, i'm pretty confused how .unbind() function doing it's doing. how removing possible handlers associated given element, if doesn't know them name?

edit: sorry if wasn't clear. question "how javascript source code .unbind() work?" know how use .unbind(). want know why works.

if see jquery-1.11.js find answer

jquery.removeevent called lastly, when call unbind()

jquery.removeevent = document.removeeventlistener ?     function( elem, type, handle ) {         if ( elem.removeeventlistener ) {             elem.removeeventlistener( type, handle, false );         }     } :     function( elem, type, handle ) {         var name = "on" + type;          if ( elem.detachevent ) {              // #8545, #7054, preventing memory leaks custom events in ie6-8             // detachevent needed property on element, name of event, expose gc             if ( typeof elem[ name ] === strundefined ) {                 elem[ name ] = null;             }              elem.detachevent( name, handle );         }     }; 

for egs try unbind(),

$('#selector').unbind('click',handler); 

above has elem,type, , handle in removeeventlistener() : function( elem, type, handle )

here

  1. elem=$('#selector')
  2. type=click
  3. handle=handler

step step call of unbind() see jquery-1.11.1.js source

  1. $('#selector').unbind('click') // calling unbind function line 8490
  2. which calls off() // line 8491(calling) => line 5201(function definition)
  3. now calling event.remove() // line 5229 => line 4374
  4. which calls removedata() removeeventlistener function called

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -