箭头函数不是语法糖,它与普通函数在this、arguments、new调用等方面存在本质差异:无独立this(继承外层词法作用域)、不能作为构造函数、无arguments对象和prototype、不支持yield;仅适用于简短无状态内联回调。
箭头函数不是语法糖,它和 function 关键字声明的函数在 this、arguments、new 调用等行为上有根本差异——用错场景会导致难以排查的 bug。
this,始终继承外层词法作用域
这是最常踩坑的一点。普通函数的 this 取决于调用方式(如 obj.method() 中 this 指向 obj),而箭头函数的 this 在定义时就固定了,无法被 call、apply、bind 或事件绑定改变。
const obj = {
name: 'Alice',
regular() {
console.log(this.name); // 'Alice'
},
arrow: () => {
console.log(this.name); // undefined(this 指向全局或 module.exports)
}
};
obj.regular();
obj.arrow();
this 的方法(如对象方法、事件处理器、Vue/React 类组件生命周期)不要用箭头函数this,比如:arr.map(x => this.process(x))(前提是 this.process 已在类构造器中绑定或为箭头函数)this 是 undefined;箭头函数则继续向上找,可能意外捕获到模块作用域的 this
prototype
试图用 new 调用箭头函数会直接报错:TypeError: xxx is not a constructor。它也没有 prototype 属性,因此无法用于需要实例化或原型链继承的场景。
const Person = (name) => { this.name = name; }; + new Person('Bob')
instanceof 判断、或要挂载共享方法到 prototype 时,必须用 function 或 class
new
arguments 对象,也不支持 yield
在箭头函数内部访问 arguments 会报 ReferenceError;它也不能用作

function* 语法,也不接受 yield)。
const regular = function() {
console.log(arguments[0]); // 正常输出
};
const arrow = () => {
console.log(arguments[0]); // ReferenceError: arguments is not defined
};
(...args) => args[0]
function* 声明async 箭头函数是合法的(const fn = async () => {}),因为 async 是修饰符,不是函数类型本身真正该用箭头函数的时刻其实很窄:当你要写一个简短的、无状态的、不依赖 this / arguments / 构造能力的内联回调时。多数人高估了它的适用范围,结果在 setTimeout 回调里丢了 this,或在类字段中误用导致无法被 bind ——这些都不是“写法更简洁”的代价,而是语义误用的必然结果。