首页 > 其他分享 >经典this指向问题

经典this指向问题

时间:2023-01-11 21:56:49浏览次数:35  
标签:function f1 f2 console 指向 问题 call 经典 return

代码如下

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({})

标签:function,f1,f2,console,指向,问题,call,经典,return
From: https://www.cnblogs.com/dou-fu-gan/p/17044998.html

相关文章