Okay let's say I have the following:
class Something {
foo = {
a: '123',
get_a() {
return this.a;
}
};
bar = {
b: '456',
get_b() {
return this.b;
},
get_c() {
return this.get_a();
}
};
}
window.s = new Something();
window.s.bar.get_c();
If I were to use s.bar.get_b() it will return '456'. Within get_b() I can reference this.b and it looks to be a reference to bar. However, when I attempt to call s.bar.get_c(), I get an error:
Uncaught TypeError: this.get_a is not a function
Well based on my understanding of this being a reference to bar, I guess that makes sense. However, I don't understand what I need to do to actually reference foo.get_a() from bar.get_c(). I've tried various things but nothing seems to work, short of just using s.foo.get_a() but I don't want to have to directly reference the s object. What am I missing here? I'm starting to suspect I'm fundamentally structuring my class wrong...
Edit: Not sure why someone felt the need to update my post to have it execute the code snippet.. seems overkill ¯_(ツ)_/¯
Anyways.. one thing I should have mentioned: in practice I'm not actually calling s.foo.get_a() from some other context outside of my class functions, which is why I mentioned not wanting to directly reference the s object. I was just putting the full path for sake of clarity!