今天不小心又掉进坑了,来来吧,看看是什么坑吧。
错误提示:
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 的执行将不会停止。
在 strict mode 中,
发生了什么?
Function.caller 和 Function.arguments 属性是不该使用的。它们都是已经被废弃的了,因为这两者泄露了函数的调用者,是不标准的,难于优化和有这潜在的性能问题。
实例
废弃的
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
了解完,是不是懵逼了,其实是自己技术没更新迭代啊。


网友评论文明上网理性发言 已有0人参与
发表评论: