Hello Stack Overflow社区,谁能解释我为什么第一种方法可行,为什么第二种返回未定义?
const o = {
name: "Bob",
age: 37,
};
/* First Method */
function info() {
return "Info: " + this.name + " -> " + this.age;
}
o.info = info;
console.log(o.info()); //Info: Bob -> 37
/* Second Method */
o.info = () => {
return "Info: " + this.name + " -> " + this.age;
}
console.log(o.info); //Undefined