473,396 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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?
Mar 30 '07 #1
1 1174
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)

Peter Rilling wrote:
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?

Mar 30 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Christoph | last post by:
newFieldElement = document.createElement( 'INPUT' ); newFieldElement.onblur = new Function( "calculatePremiumOptionTotal( this );" ); In my (dynamically generated) javascript, I've never had a...
1
by: lawrence | last post by:
I'm trying to gain a better understanding of javascript by studying examples. I noticed this in an online tutorial. I don't get the use of "this". >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> You might want...
3
by: Oliver Saunders | last post by:
can someone please tell me why everytime i try and pass this to a js function i can't seem to use it for anything: <html> <head> <script language="javascript"> function a(fromlink) {...
7
by: Shapper | last post by:
Hello, I have an ASP:ImageButton where I want to call a function and pass a string: OnClick="Change_Photo("John")" I am having problems with "". I tried
2
by: Bryan | last post by:
Hello all, Can anyone explain when one should use the "document" object and when one should use the "this" object? Also, is the "self" object the same as the "document" or "this" object?
1
by: studen771 | last post by:
Thanks in advance to anyone who can help :): I have an .aspx page that creates javascript on the fly within a button click event handler. The script creates a function AND CALLS THAT SAME...
5
by: sunsande | last post by:
Hi there! Suppose you have N checkboxes on a MSAccess form and you want that every from them to show it's name on it's OnClick event. So you do: Private Sub checkbox1_Click() MsgBox...
2
Plater
by: Plater | last post by:
I am having trouble with my script in IE(IE6) and how it treats a "this". I am thinking it might have something to do with my event wrapper function(see code) but would like to keep that wrapper. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.