JavaScript参考手册
错误 | Errors
Errors: Deprecated caller or arguments usage
信息
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.caller
并arguments.callee.caller
已弃用(请参阅参考文章以获取更多信息)。
'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
已弃用(请参阅参考文章以获取更多信息)。
'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
错误 | Errors相关
JavaScript 是一种高级编程语言,通过解释执行,是一门动态类型,面向对象(基于原型)的解释型语言。它已经由ECMA(欧洲电脑制造商协会)通过 ECMAScript 实现语言的标准化。它被世界上的绝大多数网站所使用,也被世界主流浏览器( Chrome、IE、FireFox、Safari、Opera )支持。JavaScript 是一门基于原型、函数先行的语言,是一门多范式的语言,它支持面向对象编程,命令式编程,以及函数式编程。它提供语法来操控文本、数组、日期以及正则表达式等,不支持 I/O,比如网络