I am having a little trouble structuring some code in JavaScript, below is an example of how I would like to use the code:
var instance = new myObject("foo", "bar");
var sub = new myObject.subObject("x", "y", "z");
instance.doSomething();
The subObject would not have access to properties of myObject (such as "foo" and "bar", in this case), rather myObject sort of simply encapsulates subObject, if you see what I mean. In this example "x", "y" and "z" are local to the instance of myObject.subObject.
Functions within myObject, such as doSomething() may themselves create some instances of myObject.subObject, and would have access to properties of myObject, such as "foo" and "bar".
So what structural form does myObject take?
Edit:
I was thinking something along these lines:
function myObject(foo, bar) {
this.foo = foo;
this.bar = bar;
this.doSomething = function() {
var a = new this.subObject("x", "y", "z");
var b = new this.subObject("1", "2", "3");
console.log(a.x, a.y, a.z, b.x, b.y, b.z);
};
this.subObject = function(x, y, z) {
this.x = x;
this.y = y;
this.z = z;
};
}