TypeError: Доступ к свойствам 'caller', 'callee' и 'arguments' запрещен
Исключение JavaScript, действующее только в строгом режиме: "'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them" возникает при использовании устаревших свойств arguments.callee, Function.prototype.caller или Function.prototype.arguments.
Сообщение
TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them (V8-based & Firefox) TypeError: 'arguments', 'callee', and 'caller' cannot be accessed in this context. (Safari)
Тип ошибки
TypeError только в строгом режиме.
Что пошло не так?
В строгом режиме используются свойства arguments.callee, Function.prototype.caller или Function.prototype.arguments, которые не должны использоваться. Они считаются устаревшими, потому что они раскрывают вызывающую функцию, являются нестандартными, сложными для оптимизации и потенциально опасными для производительности.
Примеры
Устаревшие function.caller или arguments.callee
Function.prototype.caller и arguments.callee устарели (см. справочные статьи для получения дополнительной информации).
"use strict";
function myFunc() {
if (myFunc.caller === null) {
return "The function was called from the top!";
}
return `This function's caller was ${myFunc.caller}`;
}
myFunc();
// TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
Function.prototype.arguments
Function.prototype.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}`);
// TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
Смотрите также
- Устаревшие и неиспользуемые возможности
- Строгий режим
Function.prototype.argumentsFunction.prototype.callerarguments.callee
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Deprecated_caller_or_arguments_usage