我以为()=> {}和function(){}的输出是相同的,但是我得到了不同的输出。
具有function(){}
var person = {};
person.name = 'egoing';
person.introduce = function(){
return 'My name is '+this.name;
}
document.write(person.introduce());
输出为
'My name is egoing'
但具有()=> {}函数,
var person = {};
person.name = 'egoing';
person.introduce = person.introduce=()=>{
return 'My name is ' +this.name}
document.write(person.introduce());
输出为
'My name is '
为什么有区别?