箭头函数的 this 继承外层普通函数作用域的 this 值,不绑定执行上下文;不能用 call/apply/bind 修改,不可作为构造函数,无 arguments 对象。

箭头函数的 this 不绑定执行上下文,而是继承外层普通函数作用域中的 this 值——这是它最核心的特点,也是和传统函数最根本的区别。
箭头函数没有自己的 this
它不会创建自己的执行上下文,所以调用时不会重新绑定 this。无论怎么调用(直接调用、作为方法、用 call/apply/bind),它的 this 都始终等于定义时所在词法作用域的 this。
- 不能用 call、apply、bind 改变它的 this
- 不能作为构造函数使用(没有 prototype,调用 new 会报错)
- 没有 arguments 对象(需用剩余参数 ...args 替代)
常见 this 继承场景
比如在对象方法或事件回调中使用箭头函数:
const obj = {
name: 'Alice',
regularFunc() {
console.log(this.name); // 'Alice'
setTimeout(function() {
console.log(this.name); // undefined(非严格模式下是 window)
}, 100);
setTimeout(() => {
console.log(this.name); // 'Alice',继承外层 regularFunc 的 this
}, 100);
}
};
再比如 React 类组件中,常把箭头函数写在类属性上,避免手动 bind:
立即学习“Java免费学习笔记(深入)”;
- ✓ 正确:`handleClick = () => { console.log(this.state); }` —— this 指向组件实例
- ✗ 错误:`handleClick() { console.log(this.state); }` + `
什么时候不该用箭头函数
需要动态绑定 this 的场景就不适合:
- 定义对象方法(希望 this 指向调用者)
- 需要使用 arguments 或 new 实例化
- Vue 中的 methods 选项(Vue 会自动绑定 this,用箭头函数反而破坏机制)
基本上就这些。记住一句口诀:箭头函数的 this 看定义位置,不看调用方式。










