Is there a way in JScript to refer to the current object's parent within a method of that object without explicitly passing the parent object to that method? For instance: if I am in a method of an object, I can refer to the current object using the this keyword. What I would like to do is use something along the lines of this.parent to refer to the current object's parent without having to pass it to the method.
Here's an example:
//oTest.oChild
function displayVal(oTest){
XDocument.UI.Alert(oTest.val1);
}
function oChild(){
//oChild object definition
this.displayVal = displayVal;
}
//oTest
function oTest(){
//oTest object definition
this.val1 = "one";
this.child = new oChild();
}
oChild is a child object of oTest. The displayVal method of the oChild object refers to the val1 property of oTest. In order to do this now, I must explicitly pass the oTest object to the displayVal method when I call it.
var myTest = new oTest();
myTest.child.displayVal(myTest);
What I would like to do is change the displayVal method so that it refers to the oTest object from within the oChild object, so it would look something like this (in pseudocode):
function displayVal(){
XDocument.UI.Alert(this.parent.val1);
}
Then, when I called the method, I wouldn't have to pass the parent object to it:
var myTest = new oTest();
myTest.child.displayVal();
Is such a thing possible? Is it even desireable? Or is my need to refer to a property on a parent object symptomatic of a larger deficiency in my object structure?