Improving Function.prototype.bind

David Bruant bruant.d at gmail.com
Mon Jan 9 03:35:11 PST 2012


Le 08/01/2012 19:47, John J Barton a écrit :
> (...)
>    window.addEventListener('load', boundOnLoad, false);
>    ...
>    window.removeEventListener('load', boundOnLoad, false);
> The JS method 1) must be bound to the correct object 2) be 
> reference-able for the removeEventListener.
>
> This combination prevents simple inline functions so commonly used by 
> JS devs from being applied to DOM event registration, a very common 
> use of inline functions. If you use an inline function without bind(), 
> then it will not have the correct object binding; if you use an inline 
> function with bind(), then it will not be reference-able for the 
> remove. (...)
If you want to use inline (anonymous) functions, you always loose the 
ability to reference the function for a later remove. This is 
independent of bind.
Inline functions are not compatible with remove.

David


More information about the es-discuss mailing list