Sorry for fuzzy post title, I can't formulate the correct name in English for this post.
For example I have such an object:
var APP = {
a : 1,
b : function(){
return this.a;
}
}
In such way, if I call console.log ( APP.b() )
than this
will be referring to APP and result will be 1
.
But how to connect to APP from sub-object? Example:
var APP = {
a : 1,
b : function(){
return this.a;
},
c : {
c1: function(){
return APP.a;
}
}
}
console.log ( APP.c.c1() ) // 1
This example works, but it's bad idea to point directly to APP. For example:
APP2 = APP;
APP = null;
console.log ( APP2.b() ); // 1
console.log ( APP2.c.c1() ); // APP is undefined
UPD:
I've got half-decision:
if I declare property c
like a method:
c : function(){
var self = this;
return {
c1: function(){
return self.b();
},
c2: function(){}
}
}
It will work, but I should call a method but not property (too much brackets) :
console.log( APP2.c().c1() )
instead of console.log( APP2.c.c1() )