[jQuery] Javascript: OOP help, accessing parent objects
I am tryign to make more use of OOP techniques in JavaScript, but most
of the OOP I have done up to now has been in class-based languages,
and I'm struggling a little with the prototype based approach used in
javascript. I know this isn't a jQuery specific question but you guys
seem like the people to ask on these things. :)
The problem is like this. Suppose I have one object that uses another
object as a variable inside it, like so:
function Contained ()
{
var self=this;
self.var1=1;
self.var2=2;
self.method1=function ()
{
};
}
function Container ()
{
var self=this;
self.varA = 'a';
self.varB = 'b';
self.containedObj = new Contained;
}
var foo = new Container;
Now suppose I want to access variables of Container from within
Contained, for example I might want method1 to return the value of
varA in Container. How would I go about doing this?