How to refer to "this" in JS event handler?

  • Thread starter Thread starter Peter Rilling
  • Start date Start date
P

Peter Rilling

Hi.

I am using Atlas and hooking a load event using add_load(...).

This is being called from the constructor of an object being created, so it
is within the context of an object (where 'this' is recognized). I want the
handler to be an instance method on the object instance.

Sys.Application.add_load( this._onLoad ) );



The problem is that when _onLoad gets called, the "this" context does not
refer to my actual object. How can I get access to the object instance
within the handler?
 
use closure when declaring the delegate. have the onLoad function accept
a parameter that is the original object, then declare the delegate as:


Sys.Application.add_load( function(){this._onLoad(this);} );


-- bruce (sqlwork.com)
 
Back
Top