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

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?
 
B

bruce barker

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top