Reference to object from grand child?

Viewed 86

Let say a I have an object:

var person= {
      firstName:"Renzo",
      getFirstName:function(){
        console.log(this);// is the person object
        return this.firstName;
      },
      address:{
        number:function(){
          console.log(this);// is the number function
          //return person.getFirstName(); // it is working
          return this.firstName;// not working           
        }
      }       
   };
   
console.log(person.getFirstName());   
console.log(person.address.number());   

I know that "this" in the getFirstName method will reference to the person object, but "this" in the number method will not reference to the person object will reference to the number function.., I can access the getFirstName method from number function referencing to the person object, that will solve the problem but...

Question: Is there way to reference the person object from the number method? without using the person variable... is there some special keyword like "this", to access the person method??

4 Answers
Related