首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Errors: Deprecated caller or arguments usage

信息

代码语言:javascript
复制
Warning: ReferenceError: deprecated caller usage (Firefox)
Warning: ReferenceError: deprecated arguments usage (Firefox)
TypeError: 'callee' and 'caller' cannot be accessed in strict mode. (Safari)

错误类型

ReferenceError发生严格模式警告。JavaScript执行不会停止。

什么地方出了错?

在严格模式下,Function.caller或使用Function.arguments属性,不应该。它们被弃用,因为它们泄漏了函数调用者,是非标准的,很难优化,并且可能是一个对性能有害的特性。

例子

Deprecated function.caller or arguments.callee.caller

Function.callerarguments.callee.caller已弃用(请参阅参考文章以获取更多信息)。

代码语言:javascript
复制
'use strict';

function myFunc() {
  if (myFunc.caller == null) {
    return 'The function was called from the top!';
  } else {
    return 'This function\'s caller was ' + myFunc.caller;
  }
}

myFunc();
// Warning: ReferenceError: deprecated caller usage
// "The function was called from the top!"

Function.arguments

Function.arguments 已弃用(请参阅参考文章以获取更多信息)。

代码语言:javascript
复制
'use strict';

function f(n) { g(n - 1); }

function g(n) {
  console.log('before: ' + g.arguments[0]);
  if (n > 0) { f(n); }
  console.log('after: ' + g.arguments[0]);
}

f(2);

console.log('returned: ' + g.arguments);
// Warning: ReferenceError: deprecated arguments usage

扫码关注腾讯云开发者

领取腾讯云代金券