Re: Functions that Implement the EventListener Interface (DOM Level 3 Events)

Rob Brackett:
> It's just frustrating, as a content author, that it's a little
> unpredictable and that it removes the easy ability to have "this"
> point to my object instead of to the DOM node that fired the event.

Do you mean unpredictable because of non-interoperability?  Then sure, I
think that’s what we all want to fix. :-)

Note this is only an issue for when you have an object that is *both* a
Function object and has a handleEvent property.  If you want an object
for you this, don’t use a function.

  var listener = {
    _state: 123,
    handleEvent: function(evt) {
      // do something with evt and this._state
    }
  };
  addEventListener(blah, listener, false);

There is a hook in Web IDL for defining what “this” will be (the
“callback this value” definition in
http://dev.w3.org/2006/webapi/WebIDL/#native-objects).  DOM Core/Events
needs to define that this value is the event target if the listener is a
Function object.

-- 
Cameron McCormack ≝ http://mcc.id.au/

Received on Thursday, 23 June 2011 23:59:43 UTC