![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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? |
#3
| |||
| |||
|
|
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 } } } } |
#4
| |||
| |||
|
|
Joost Diepenmaat <jo... (AT) zeekat (DOT) nl> writes: 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.onReadyStateChange = function(){ * * * * * * * *if (myFoo.myFooVar == 0) *// accessit here * * * * * * * *{ * * * * * * * * * // do this * * * * * * * *} * * * * } * } } Anyway. HTH -- Joost Diepenmaat | blog:http://joost.zeekat.nl/| work:http://zeekat.nl/ |
#5
| |||
| |||
|
|
SirCodesALot <sjour... (AT) gmail (DOT) com> writes: 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/ |
#6
| |||
| |||
|
|
On Mar 12, 2:06 am, Joost Diepenmaat wrote: snip 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 } } } } snip but thats not necessarily a clousre. |
|
.function being a first class object in Javascript you can access it using "this" |
![]() |
| Thread Tools | |
| Display Modes | |
| |