Improving Function.prototype.bind

Andrea Giammarchi andrea.giammarchi at
Mon Jan 9 01:44:12 PST 2012

Bear in mind e.currentTarget may be undefined .... e.g. in an about:blank

document.addEventListener("click", function (e)
{console.log(e.currentTarget)}, false);

would be null

On Mon, Jan 9, 2012 at 9:29 AM, David Bruant <bruant.d at> wrote:

>  Le 09/01/2012 06:29, Brendan Eich a écrit :
>  On Jan 8, 2012, at 7:20 PM, John J Barton wrote:
>  On Sun, Jan 8, 2012 at 3:35 PM, Brendan Eich <brendan at> wrote:
>>    Firebug uses a library bind a lot, and we continually struggled with
>> the memoization problem; we did not try to solve it in part because we
>> hated Firebug's bind: it made debugging even more painful since it messes
>> up the call stack. Using the ES bind() ends up not being a win, since I now
>> have exactly the same problems.
>>  I have a question: why is bind used so much in Firebug for event
>> listeners, when the DOM guarantees to dispatch them with the event target
>> bound to |this|? Way back in '95, I created event handlers but did not add
>> bind (it had to be discovered later). But dynamic |this| binding combined
>> with DOM event target-based listening and handling kept this properly
>> bound. What has changed?
>>   Sorry I don't know what you mean here.
>  Why all the this-binding in Firebug if (as you suggested and a grep
> seems to confirm [but I skimmed]) the methods being this-bound are all or
> mostly event listeners? The DOM dispatches event handlers on the correct
> |this|.
> Relevant related documentation:
> David
> _______________________________________________
> es-discuss mailing list
> es-discuss at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list