经典this指向问题

代码如下

function f1() {
  this.p = function(){
    // 这里 this 跟的是p这个func,谁调用p,就跟谁
    console.log(this);
  }
  return this
}
function f2() {
  this.p = ()=> {
    // 这里this 跟的是f2
    console.log(this);
  }
  return this
}
f1().p.call({})
f2().p.call({})
posted @ 2023-01-11 21:43  dou_fu_gan  阅读(30)  评论(0)    收藏  举报