Improving Function.prototype.bind

Andrea Giammarchi andrea.giammarchi at gmail.com
Mon Jan 9 04:21:49 PST 2012


sorry, wrong debug, currentTarget is always the expected one ... my bad

On Mon, Jan 9, 2012 at 10:44 AM, Andrea Giammarchi <
andrea.giammarchi at gmail.com> wrote:

> Bear in mind e.currentTarget may be undefined .... e.g. in an about:blank
> page
>
> 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 gmail.com> 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 mozilla.com>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:
>> https://developer.mozilla.org/en/JavaScript/Reference/Operators/this#As_a_DOM_event_handler
>>
>> David
>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120109/92171288/attachment.html>


More information about the es-discuss mailing list