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