ReferenceError: deprecated caller or arguments usage - JavaScript 编辑
The JavaScript strict mode-only exception "deprecated caller or arguments usage" occurs when the deprecated Function.caller
or Function.arguments
properties are used.
Message
TypeError: 'arguments', 'callee' and 'caller' are restricted function properties and cannot be accessed in this context (Edge) Warning: ReferenceError: deprecated caller usage (Firefox) Warning: ReferenceError: deprecated arguments usage (Firefox) TypeError: 'callee' and 'caller' cannot be accessed in strict mode. (Safari)
Error type
A strict-mode-only warning that a ReferenceError
occurred. JavaScript execution won't be halted.
What went wrong?
In strict mode, the Function.caller
or Function.arguments
properties are used and shouldn't be. They are deprecated, because they leak the function caller, are non-standard, hard to optimize and potentially a performance-harmful feature.
Examples
Deprecated function.caller or arguments.callee.caller
Function.caller
and arguments.callee.caller
are deprecated (see the reference articles for more information).
'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
is deprecated (see the reference article for more information).
'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
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论