我想了解为什么这段代码返回一个值,而第二个代码返回undefined
;
function personName(){
console.log(this.name);
}
const obj =
{
name: "David",
greetings: function() {
return `Hello ${this.name}`
}
}
console.log( obj.greetings() );
function personName(){
console.log(this.name);
}
const obj = {
name: "David",
greetings: () => `Hello ${this.name}`
}
console.log( obj.greetings() );