'Inner function not printing this value? [duplicate]
Want to see why printName() function console.log not printing the value? What is the value this holds?
const person = {
firstname: 'John',
lastname: 'Muir',
name: 'hello',
fullname() {
const name = 'Tim';
this.name = 'Tim';
console.log(JSON.stringify(this));
console.log('First name ' + this.firstname);
console.log('Last name '+ this.lastname);
printName = function () {
console.log('name again ' + this.name);
};
printName();
}
}
person.fullname();
Output
{"firstname":"John","lastname":"Muir","name":"Tim"}
First name John
Last name Muir
name again undefined
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
