Connecting Tech Pros Worldwide Help | Site Map

Javascript Object - Syntax Help

  #1  
Old March 11th, 2008, 09:55 PM
SirCodesALot
Guest
 
Posts: n/a
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.onReadyStateChange = function(){
if (this.myFooVar == 0) <----------- Here is the
problem
{
// do this
}
}
}
}

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

Thanks in advance for your help.

-SJ

I
  #2  
Old March 11th, 2008, 10:15 PM
Joost Diepenmaat
Guest
 
Posts: n/a

re: Javascript Object - Syntax Help


SirCodesALot <sjourdan@gmail.comwrites:
Quote:
How do I refer to the "this.myFooVar" from the foo object when
defining the sub-sub function for on readyStateChange? 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.onReadyStateChange = function(){
if (myFoo.myFooVar == 0) // access it here
{
// do this
}
}
}
}

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
  #3  
Old March 11th, 2008, 10:15 PM
Joost Diepenmaat
Guest
 
Posts: n/a

re: Javascript Object - Syntax Help


Joost Diepenmaat <joost@zeekat.nlwrites:
Quote:
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
Quote:
ao.onReadyStateChange = function(){
if (myFoo.myFooVar == 0) // access it here
{
// do this
}
}
}
}
Anyway.
HTH

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
  #4  
Old March 12th, 2008, 12:45 AM
SirCodesALot
Guest
 
Posts: n/a

re: Javascript Object - Syntax Help


On Mar 11, 4:10*pm, Joost Diepenmaat <jo...@zeekat.nlwrote:
Quote:
Joost Diepenmaat <jo...@zeekat.nlwrites:
Quote:
just use a closure:
>
Quote:
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
>
Quote:
* * * * ao.onReadyStateChange = 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!!
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is a JavaScript Object? Yene answers 5 October 19th, 2009 06:47 PM
JavaScript Object and Prototypes Frinavale answers 23 March 16th, 2009 04:09 PM
Javascript Object Expected Error, Master Pages & DetailsView Confl Greg answers 4 April 5th, 2006 06:25 PM
JavaScript Object Model Resources Digital answers 5 January 3rd, 2006 12:25 PM
Accessing html element or client side javascript object from C#. Gary answers 2 November 15th, 2005 06:21 AM