jQuery adds a wrapper around callback functions, and also collects
them to data object.
In case you want to remove all click handlers or all handlers in a
namespace, it just goes through that data object for that Element, and
removes each function that is stored there.

2011/3/23 Mark McDonnell <mark.m...@gmail.com>:
> that makes sense thanks :)
>
> But I'm building my own js library that abstracts the api between browsers 
> and obviously there is the chance that a user with will specify an anonymous 
> function as the handler. How does a library like jQuery's bind() method 
> handle these situations ?
>
> Sent from my iPhone
>
> On 23 Mar 2011, at 13:36, Poetro <poe...@gmail.com> wrote:
>
>> 2011/3/22 Mark McDonnell <mark.m...@gmail.com>:
>>> I'm having a bizarre issue removing an event listener (this occurs in both
>>> Firefox and Chrome).
>>>
>>> If I run the following code via the console…
>>>
>>> document.getElementsByTagName('body')[0].addEventListener('click',
>>> function(e){ alert(e); }, false);
>>>
>>> …the event listener is added successfully, but if I run the following code
>>> also in the console to remove the event listener it doesn't appear to
>>> actually remove the event listener?...
>>>
>>> document.getElementsByTagName('body')[0].removeEventListener('click',
>>> function(e){ alert(e); }, false);
>>>
>>> …I'm really confused why this wouldn't work?
>>
>> Those listeners are totally different functions. If you are planning
>> to remove an event listener, make it a separate function, and use that
>> with addEventListener and removeEventListener. For example:
>>
>> function clickHandler(e) {
>>  alert(e);
>> }
>> document.getElementsByTagName('body')[0].addEventListener('click',
>> clickHandler, false);
>> // ...
>> document.getElementsByTagName('body')[0].removeEventListener('click',
>> clickHandler, false);
>>
>> Creating anonymous functions each time creates 2 different functions,
>> so you cannot remove it, as u haven't added that, but a different
>> function, that has the same implementation. Just think of:
>>
>> var a = {}, b = {};
>> alert(a === b); // false
>>
>> --
>> Poetro
>>
>> --
>> To view archived discussions from the original JSMentors Mailman list: 
>> http://www.mail-archive.com/jsmentors@jsmentors.com/
>>
>> To search via a non-Google archive, visit here: 
>> http://www.mail-archive.com/jsmentors@googlegroups.com/
>>
>> To unsubscribe from this group, send email to
>> jsmentors+unsubscr...@googlegroups.com
>
> --
> To view archived discussions from the original JSMentors Mailman list: 
> http://www.mail-archive.com/jsmentors@jsmentors.com/
>
> To search via a non-Google archive, visit here: 
> http://www.mail-archive.com/jsmentors@googlegroups.com/
>
> To unsubscribe from this group, send email to
> jsmentors+unsubscr...@googlegroups.com
>



-- 
Poetro

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/jsmentors@jsmentors.com/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/jsmentors@googlegroups.com/

To unsubscribe from this group, send email to
jsmentors+unsubscr...@googlegroups.com

Reply via email to