-1

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
  • 91,378
  • 50
  • 226
  • 356
Aljoša Srebotnjak
  • 1,241
  • 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
  • 572,313
  • 128
  • 898
  • 1,281