this 是「运行时绑定」的:函数定义时不知道 this 是谁,只有被调用的那一刻才确定。判定规则按优先级:new 绑定 > 显式绑定(call/apply/bind)> 隐式绑定(对象方法调用)> 默认绑定(严格模式 undefined,非严格 window)。
箭头函数没有自己的 this,它继承外层词法作用域的 this——这正是它在回调中好用的原因,再也不用 var self = this 或 .bind(this) 了。
const obj = { name: 'A', greet() { setTimeout(() => console.log(this.name), 100); } }; obj.greet(); // A(箭头函数继承 obj 的 this) function f() { console.log(this); } f.call({ x: 1 }); // { x: 1 } 显式绑定 class C { m = () => this; } // 类字段箭头函数永久绑定实例