how can i use this of obj in sayHi()
i want this in sayHi to refer to this in obj what changes should i add to sayHi so it prints harry potter instead of undefined
let obj = {
fullName: "Harry Potter",
person: {
sayHi: function(){
return "This person's name is " + this.fullName
}
}
}
is there another way than this obj.person.sayHi.call(obj) or obj.person.sayHi.apply(obj) to do it;
bindinstead ofcall. It's a similar concept though: developer.mozilla.org/de/docs/Web/JavaScript/Reference/…varinside function is private / local scopeobj.fullNameif you don't want to usecallorapply.thisin this case points toperson. Not sure if that's what you intend to do