箭头函数是function实例但无this、arguments、super、new.target和prototype属性,不能作为构造函数;其this继承外层词法作用域且不可变;arguments需用剩余参数替代;name属性只读且不可枚举;length仅统计常规形参个数。

箭头函数定义后生成的函数对象,和普通函数表达式创建的对象在类型上一致(都是 Function 实例),但关键属性表现有明显差异——它没有自己的 this、arguments、super 和 new.target,也不具备 prototype 属性。
不继承 arguments,也没有 arguments 对象
箭头函数内部无法访问 arguments 类数组对象。调用时传入的参数只能通过显式命名参数或剩余参数(...args)获取。
- 普通函数中:
function f() { console.log(arguments[0]); }可正常输出第一个实参 - 箭头函数中:
const f = () => console.log(arguments[0]);会报ReferenceError: arguments is not defined - 替代写法:
const f = (...args) => console.log(args[0]);
没有 prototype 属性,不能作为构造函数
箭头函数的 prototype 属性为 undefined,因此不能用 new 调用,否则会抛出 TypeError。
const Person = () => {}; console.log(Person.prototype); // undefinednew Person(); // TypeError: Person is not a constructor- 而普通函数:
function Person() {}的Person.prototype是一个可扩展的对象
this 绑定不可变,且始终继承外层词法作用域
箭头函数不绑定自己的 this,而是沿作用域链向上查找最近的非箭头函数上下文的 this 值,并在定义时就固化下来。
- 无法通过
call、apply或bind改变其this - 在对象方法中使用时,
this指向外层(如构造函数实例或模块顶层),而非该对象本身 - 常见用途:避免回调中
this丢失,例如setTimeout(() => console.log(this.name), 100)
name 属性存在,但不可枚举且通常为 "" 或推导名
箭头函数的 name 属性是只读的,值取决于赋值方式:
- 直接赋给变量:
const foo = () => {};→foo.name === "foo" - 作为对象方法:
obj.method = () => {};→obj.method.name === ""(匿名) - 注意:
Object.getOwnPropertyDescriptor(foo, 'name').enumerable为false
length 属性反映形参数量,但不计入剩余参数
length 返回的是“常规参数”个数(即未被 ... 包裹的参数数量),与普通函数一致。
-
(a, b) => a + b→length === 2 -
(a, ...rest) => a→length === 1 -
() => {}→length === 0
Java免费学习笔记:立即使用
解锁 Java 大师之旅:从入门到精通的终极指南











