473,471 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Gaining reference to an outer this?

Howdy All!

Can anyone help with using "this" here please?

function TestObject()
{
this.one = one;
this.two = two;
} // end TestObject constructor

function one()
{
// "this" would refer to a TestObject (~1~)

// Make a select control.. and assign it an onChange handler.
var dateSelect = document.createElement ("select");
dateSelect.onchange =
function hide()
{
// "this" refers to a Select object.

// How can I refer to the TestObject at (~1~) so I can
// call two() on that particular instance?
}; // end hide function
} // end function one

function two()
{
alert ("in function two");
} // end function two

Thanks for any help!

Rob
:)
Jul 20 '05 #1
2 1811
"Robert Mark Bram" <re********@remove.this.optusnet.com.au> writes:
function one()
{
// "this" would refer to a TestObject (~1~)
Correct.
// Make a select control.. and assign it an onChange handler.
var dateSelect = document.createElement ("select");
Add:
var thisTestObject = this;
to get a variable as reference to the testObject, instead of just
"this".
dateSelect.onchange =
function hide()
{
// "this" refers to a Select object.
Correct.
// How can I refer to the TestObject at (~1~) so I can
// call two() on that particular instance?


Use the variable "thisTestObject". The function expresion "hide"
creates a closure, so it remembers the value of the "thisTestObject"
variable.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
Thank you Lasse!
Add:
var thisTestObject = this;
to get a variable as reference to the testObject, instead of just
"this".


It works perfectly. :)

Rob
:)
Jul 20 '05 #3

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

Similar topics

2
by: panzy | last post by:
Hi, I have this structure: <a> <repeated_part> <just_the_same_thing_and_more/> </repeated_part> </a> <b>
2
by: Squeamizh | last post by:
This is something that has been bothering me for a while. Assume the following two class definitions: class Inner { int a; int b; ... };
51
by: Senthil | last post by:
Hi, I am reading Modern C++ Design where Anderi quoted "C++ does not allow references to references". Assume i have DoThat(const string& strData2) { ... }
175
by: Sai Hertz And Control Systems | last post by:
Dear all, Their was a huge rore about MySQL recently for something in java functions now theirs one more http://www.mysql.com/doc/en/News-5.0.x.html Does this concern anyone. What I...
12
by: Mortos | last post by:
I need some quick advice. I just need to reference a containing class from the nested class. I'm familiar with Java but C# is proving tricky. public BigClass { public int ID_BigClass = -99; ...
0
by: Stephen Cairns | last post by:
I have the following rpx file in a .Net solution and I am getting the following build errors which are driving me crazy and ive no idea where I have went wrong. The build errors I'm getting are as...
8
by: ST | last post by:
Hello everyone, Can anyone help me with this error above when I debug my web app project in vstudio.net?? I can't figure it out! It was working fine for months, and now all of a sudden it's not!!...
3
by: Ray Stevens | last post by:
I have a dataclass that was created by a code generator. A snippit of its output is as follows: namespace SoftwareAG.EntireX.NETWrapper.Generated.laf801n1.Groups { public class Laf801n1
5
by: No bother | last post by:
I am using 5.0.26-NT on Windows 2000. I have need to use a reference in the outer from clause in a subquery in the select clause. Consider the following example: Select (select b.baitID from...
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.