Let's say I have an object:
var person= {
firstName:"Renzo",
getFirstName:function(){
console.log(this);
return this.firstName;
},
address:{
number:function(){
console.log(this);
return this.firstName;
}
}
};
console.log(person.getFirstName());
console.log(person.address.number());
Run codeHide resultI know that the "this" in the getFirstName method refers to the person object, but the "this" in the number method will not refer to the person object, refers to the number .. function, I can access the getFirstName method from the number function referencing the object person who will solve the problem, but ...
Question:
Is there a way to refer to a person object from a number method? without using a human variable ... is there any special keyword, such as "this", to access the person method?
source
share