箭头函数无this、不能new、无arguments和prototype,适用于需词法绑定this的场景,但不适用于构造函数、动态this或生成器。

箭头函数没有自己的 this,这点必须时刻记住
箭头函数不绑定自己的 this,它会沿作用域链向上查找最近一层普通函数的 this。这意味着:
const obj = {
name: 'Alice',
regular() {
console.log(this.name); // 'Alice'
setTimeout(function() {
console.log(this.name); // undefined(非严格模式下是 global)
}, 100);
},
arrow() {
console.log(this.name); // 'Alice'
setTimeout(() => {
console.log(this.name); // 'Alice' ✅
}, 100);
}
};如果你在事件监听器、定时器、Promise 回调里需要访问对象上下文,用箭头函数能省去 bind(this) 或缓存 const self = this 的麻烦。但反过来说——如果真需要动态 this(比如用 call/apply 显式指定),那就不能用箭头函数。
箭头函数不能用作构造函数,也不能使用 new
它没有 [[Construct]] 内部方法,调用时会直接抛错:
const Person = () => {};
new Person(); // TypeError: Person is not a constructor所以所有需要实例化的类、工厂函数、或依赖 prototype 扩展的场景,都得用 function 声明或 class。另外,箭头函数也没有 arguments 对象,要用剩余参数 ...args 替代。
单参数、单表达式可省略括号和 return,但别为了简洁牺牲可读性
语法糖确实方便,但容易引发歧义:
-
x => x * 2✅ 等价于function(x) { return x * 2; } -
x => { x * 2 }❌ 没有return,返回undefined -
x => ({ id: x })✅ 圆括号包裹对象字面量,避免被解析成代码块
箭头函数没有 prototype 属性,也无法用 yield
它不是“可调用对象”的完整实现:
const fn = () => {};
console.log(fn.prototype); // undefined
function* gen() { yield 1; } // OK
// const bad = * => {}; // SyntaxError这意味着你无法给箭头函数添加原型方法,也不能把它写成生成器。如果项目里要兼容旧引擎(如 IE),还得知道:箭头函数是 ES6+ 特性,Babel 转译后会变成普通函数 + _this 闭包,但 this 行为已固化,转译不会还原动态绑定逻辑。
箭头函数不是普通函数的“升级版”,它是不同语义的工具。什么时候该用、什么时候不该用,关键看你要不要 this 动态绑定、要不要实例化、要不要 arguments 或 prototype——这些边界一旦模糊,调试时的困惑远大于写代码时那几毫秒的便利。










