I have a couple of nested objects, where A is always a part of B.
May I use the following code to access owner's properties and methods?
function A( owner ) {
this.value = function () { return owner.value() + 1 };
}
function B() {
this.value = function () { return 1; };
this.a = new A( this );
}
var b = new B();
alert( b.a.value() );
Actually, it works. But I would like to know whether it is correct or not.
this.fooreferences a field of a new object whose prototype isA.prototypeif your call site invokesnew A()(as opposed to justA()orA.call(someObject), in which casethisdepends on the way the function is called). \$\endgroup\$