为什么我不能在这个草率模式函数中访问 arguments.callee?

Why can't I access arguments.callee in this sloppy-mode function?

我试图在下面的简单函数中访问 arguments.callee 属性,但我无法访问,因为该函数会引发错误。

function foo(a = 50, b) {
  console.log(arguments.callee);
}

foo(10, 50);

为什么会这样? 严格模式下函数好像是运行,但是怎么可能呢,我没说'use strict';

我是 运行 这个 Chrome。

如果您在函数声明中使用高级(现代,ES6+)语法,则会像在严格模式下一样自动创建一个 arguments 对象 - 在您的情况下,它是默认参数初始化程序。该功能实际上不是严格模式 - 例如你仍然可以在那里使用 with 语句,但是 arguments 对象不再向后兼容 ES5 之前的代码。

note on FunctionDeclarationInstantiation:

A mapped argument object is only provided for non-strict functions that don't have a rest parameter, any parameter default value initializers, or any destructured parameters.

除了不再有 .callee 之外,它也不反映对参数变量的赋值(这总是很令人惊讶,请参阅 JavaScript: why does changing an argument variable change the `arguments` "array"? or )。

基本上 arguments.callee 已被 ES5 弃用,但为了向后兼容,该语言只能在您选择现代语法时选择不提供它,例如使用严格模式或非简单参数声明。