为什么箭头函数/方法的“this”在这里===窗口?

qyswt5oh  于 2021-09-23  发布在  Java
关注(0)|答案(0)|浏览(202)

此问题已在此处找到答案

箭头功能和此[重复](5个答案)
对象文本/初始值设定项中的自引用(25个答案)
三天前关门。
我知道箭头函数没有自己的“this”并引用其父函数,因此我假设它指向其父函数的“this”,即obj。如果有人能回答这个问题,我将不胜感激。

var obj = {
   fullname: 'Jack',
   prop: {
      fullname: 'John',
      getFullname: () => {
         return this.fullname;
      }
   }
};

console.log(obj.prop.getFullname()); // undefined, as this is window not obj or prop
var test = obj.prop.getFullname;
console.log(test()); // undefined

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题