0

if i have :

var obj= {
    a:"something", 
    b:{ 
        a:function (){
        // Can I access obj properties through the this keyword here
        }
    }
};

Can I access properties of obj through the this keyword in the obj.b.a function?

Eric
  • 95,302
  • 53
  • 242
  • 374
Aljoša Srebotnjak
  • 1,311
  • 2
  • 12
  • 13

1 Answers1

0

Short answer: No.

Long answer: There could be many properties on many objects pointing to the object. Which one would be the parent? Also, read here how the this keyword really works: It only points to the obj.b object when your function is called with obj.b.a().

However, you can still use the obj variable as a reference. In this answer I have discussed the differences to this.

Community
  • 1
  • 1
Bergi
  • 630,263
  • 148
  • 957
  • 1,375