← 返回完整题库
ES6困难

箭头函数和普通函数有啥区别?箭头函数能当构造函数吗?

参考答案

区别对比

| 维度 | 箭头函数 | 普通函数 |
| --- | --- | --- |
| this | 词法(定义时外层作用域的 this) | 动态(调用时决定) |
| arguments | ❌ 没有 | ✅ 有 |
| new 调用 | ❌ 不能作构造器(无 prototype/[[Construct]]) | ✅ |
| prototype | ❌ undefined | ✅ |
| super / new.target | ❌ | ✅(普通函数有 new.target) |
| yield | ❌ 不能做 Generator | ✅ function* |
| call/apply/bind 改 this | ❌ 无效 | ✅ 有效 |
| 语法 | 表达式,可省略 return 与 {} | 声明/表达式 |
| 提升 | 变量形式,无函数声明提升 | 函数声明会提升 |
| 适用 | 回调、短逻辑、需要保留 this | 方法、构造器、需要 arguments |

能不能当构造函数

不能。

const F = () => {};
new F();   // TypeError: F is not a constructor

原因:箭头函数没有 [[Construct]] 内部方法,也没有 prototype 属性;new 需要创建对象并绑定 this,而箭头函数的 this 是词法绑定的,无法被替换。

其他细节

  1. **箭头函数不能有 arguments**,需要参数用 rest:(...args) => args。
  2. 不能用作对象方法(否则 this 不是对象本身)。
  3. **不能用作 addEventListener 里需要 this 指向元素的回调**(要用 function)。
  4. 箭头函数返回对象字面量要加括号:() => ({ a: 1 })。
  5. Function.prototype.toString 能看到箭头语法;name 会从变量名推断。
  6. 箭头函数不能被子类化:class X extends Arrow 报错。

选择建议

  • 数组方法、Promise 回调、定时器、需要保留外层 this → 箭头函数。
  • 对象方法、class 方法、构造器、需要 arguments/new.target/yield → 普通函数。
  • Vue 的 methods、React 的类组件方法 → 普通函数(或用 class 字段箭头绑定实例)。

一句话

箭头函数 = 没有 this/arguments/prototype 的"轻量函数";它的定位是"回调与短逻辑",不是"通用函数替代品"。

本题来自 计算机知识面试题库,共 921 道题。