js 严格模式使用 caller
在严格模式下,使用 caller 属性会抛出一个错误,因为在严格模式下,函数的 caller 属性已被禁用。
例如:
'use strict';
function foo() {
console.log(foo.caller); // 抛出错误
}
foo();
输出:
Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
因此,在严格模式下,应该避免使用 caller 属性。
原文地址: https://www.cveoy.top/t/topic/g8v6 著作权归作者所有。请勿转载和采集!