Improving Function.prototype.bind

Andrea Giammarchi andrea.giammarchi at
Mon Jan 9 03:56:10 PST 2012

indeed ... inline functions are problem number 2, anonymous or not, unless
the removeEventListener is not performed inside the function itself so that
at least the function name could be reused while if anonymous and "use
strict" is in place there's no way to know which function is it.

However, two inline functions cannot possibly be the same object so, as
problem itself, I would not even consider to solve this.


On Mon, Jan 9, 2012 at 12:35 PM, David Bruant <bruant.d at> wrote:

> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list