473,785 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript Object - Syntax Help

Can someone help me with this syntax, I have the following javascript
object:

function foo()
{
this.myFooVar = 0;
this.doThis = function (){
var ao = new AnotherObject() ;
ao.onReadyState Change = function(){
if (this.myFooVar == 0) <----------- Here is the
problem
{
// do this
}
}
}
}

How do I refer to the "this.myFoo Var" from the foo object when
defining the sub-sub function for on readyStateChang e? Did i need to
use a keyword like parent?

Thanks in advance for your help.

-SJ

I
Mar 11 '08 #1
3 1409
SirCodesALot <sj******@gmail .comwrites:
How do I refer to the "this.myFoo Var" from the foo object when
defining the sub-sub function for on readyStateChang e? Did i need to
use a keyword like parent?
just use a closure:

function foo()
{
this.myFooVar = 0;
var myFoo = this; // save the this object
this.doThis = function (){
var ao = new AnotherObject() ;
ao.onReadyState Change = function(){
if (myFoo.myFooVar == 0) // access it here
{
// do this
}
}
}
}

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Mar 11 '08 #2
Joost Diepenmaat <jo***@zeekat.n lwrites:
just use a closure:

function foo()
{
this.myFooVar = 0;
var myFoo = this; // save the this object
this.doThis = function (){
var ao = new AnotherObject() ;
var myFoo = this; // or here, which seems like a more
// logical place
ao.onReadyState Change = function(){
if (myFoo.myFooVar == 0) // access it here
{
// do this
}
}
}
}
Anyway.
HTH

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Mar 11 '08 #3
On Mar 11, 4:10*pm, Joost Diepenmaat <jo...@zeekat.n lwrote:
Joost Diepenmaat <jo...@zeekat.n lwrites:
just use a closure:
function foo()
{
* this.myFooVar = 0;
* var myFoo = this; // save the this object
* this.doThis = function (){
* * * * var ao = new AnotherObject() ;

* * * * * var myFoo = this; * * // or here, which seems like a more
* * * * * * * * * * * * * * * * // logicalplace
* * * * ao.onReadyState Change = function(){
* * * * * * * *if (myFoo.myFooVar == 0) *// accessit here
* * * * * * * *{
* * * * * * * * * // do this
* * * * * * * *}
* * * * }
* }
}

Anyway.
HTH

--
Joost Diepenmaat | blog:http://joost.zeekat.nl/| work:http://zeekat.nl/
Thanks a alot for your reponse. Just what I needed!!
Mar 11 '08 #4

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

Similar topics

2
11295
by: Gary | last post by:
Hi, I am developing desktop application. In the desktop application am loading a html page, i want to acces html element value from C# code. Can anyone help me? how to access a html element or clientside javascript object from C# code. Note: i am not using web server. TIA,
2
1398
by: Dean Slindee | last post by:
Is there any way to refer to the .text property of a status bar panel thru object syntax, like below (the inner "for" does not work): Public Function FormStatusBarPaint(ByVal frm As Form) As Integer Dim obj As New Control
5
1438
by: Digital | last post by:
Hi, I'm looking for links to the JS object model for the not-as-popular properties and methods. I've found things like hasOwnProperty, isEnumerable, ===, prototype, and others by searching for things I was trying to do. I havn't been able to find an all-encompassing object model online. I've found good ones for events and properties of specific controls and a lot of different models that describe all the well-known DOM...
3
1458
by: Rob R. Ainscough | last post by:
What sick saddistic person came up with the JavaScript language syntax? And was it the same person (or group of people) that came up with the HTML syntax?? OMG, has no one noticed this hopeless poor choice of language syntax? And why-o-why is it case sensitive? Is it just a carry over from light weight parsers? If we can't get out of this nightmare because of compatibility sake -- where and how is this going to progress to a point of...
2
2273
by: mikevanoo | last post by:
Hi, Can anyone work out why the following doesn't work. For some reason, when you dynamically add a button to the document from a Javascript object it can't then reference the properties of the object like a "normal" button. Any ideas? Thanks in advance, Mike.
1
2869
by: KDawg44 | last post by:
HI, I am using jsgraph to draw some graphs. I want to be able to update these graphs by calling a javascript function to update data. I have a div to display the graph that looks like this: <div id = 'div1'> <script language="JavaScript"> <!--
23
2660
Frinavale
by: Frinavale | last post by:
JavaScript is a very strange place for me... So, I decided that, before I attempt to create an Object, I should first learn about Objects. I had actually created one before with the help of a tutorial. The tutorial was complicated because showed me how to create a JavaScript Object that is a representation my .NET Object and how to get the two to "work together as one".... apparently the tutorial was not very clear about what was going on in...
3
5456
Frinavale
by: Frinavale | last post by:
I've created a few ASP.NET Ajax Enable Server controls. There are 2 components to these controls: a server side Object that deals with the server side stuffs, and a client side Object that deals with the client side stuff. My controls are pretty nifty and quite useful but I keep coming back come back to the same question: How do I pass data from the JavaScript Object to the Server code? Up 'til now I've been using HiddenFields in...
5
1350
by: Yene | last post by:
What is a JavaScript Object? if there is a such thing help pls.
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10092
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8973
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3647
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.