Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Custom event handlers and the "this" keyword

0 views
Skip to first unread message

dmc...@netsecurecanada.com

unread,
Dec 1, 2008, 5:53:04 PM12/1/08
to
Hi,

We've implemented a custom event handling mechanism which involves
assigning a custom IDispatch event handler to a particular event. We
store the existing event handlers that are already registered for the
event in our object, and after our object handles the event, it
invokes the event (via DispID=0) on the existing IDispatch handlers
that were originally attached to the object. It works fine - our
class handles the event, and then the event is dispatched to the
existing handlers for processing. However, things get funky when the
"this" keyword is used in an inline context:

e.g.

<form id='someForm'>
<input type='button' id=someButton onclick='someFn(this.id);'>
</form>

function someFn(var str)
{
alert(str);
}


In this circumstance when our custom handler isn't attached, the
output of someFn is "someButton". However, when we attach our custom
handler, and proxy the call to the original handler, the output of
someFn is "someForm". it appears that the "this" keyword no longer
points to the element, but rather its parent. Does anyone have any
idea why this is happening, and how to fix the context of the call
such that the "this" parameter will point to the input rather than the
form?

Thanks,
Dan

Igor Tandetnik

unread,
Dec 1, 2008, 6:11:45 PM12/1/08
to
dmc...@netsecurecanada.com wrote:
> We've implemented a custom event handling mechanism which involves
> assigning a custom IDispatch event handler to a particular event. We
> store the existing event handlers that are already registered for the
> event in our object, and after our object handles the event, it
> invokes the event (via DispID=0) on the existing IDispatch handlers
> that were originally attached to the object. It works fine - our
> class handles the event, and then the event is dispatched to the
> existing handlers for processing. However, things get funky when the
> "this" keyword is used in an inline context:

See

http://msdn.microsoft.com/en-us/library/sky96ah7.aspx
http://msdn.microsoft.com/en-us/library/asd22sd4.aspx

in particular parts about DISPID_THIS.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


0 new messages