TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
时间: 2023-11-08 07:54:04 浏览: 85
这个错误通常发生在 JavaScript 中,它是因为在严格模式下访问了 "caller"、"callee" 或 "arguments" 属性,或者尝试在严格模式下对这些属性进行调用。在严格模式下,这些属性被视为不安全的语言特性,因此不允许访问。要解决这个问题,你需要确保所有代码都不会在严格模式下访问这些属性,或者你可以考虑不使用严格模式。
相关问题
webuploader.fis.js:4920 Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
这个错误通常是在严格模式下访问 'caller', 'callee' 和 'arguments' 属性所导致的。这些属性只在非严格模式下可用,并且在严格模式下,试图访问它们会导致错误。解决这个问题的方法有两种:
1. 避免在严格模式下访问这些属性。您可以将代码中的严格模式去掉,或者避免在严格模式下使用那些需要访问这些属性的函数。
2. 使用其他方式获取相同的信息。例如,可以使用 Function.caller 属性来获取调用当前函数的函数,而不是使用 arguments.callee.caller 属性。同样的,可以使用 Function.apply 或 Function.call 方法来代替 arguments 对象。
下面是一个示例代码:
```
function foo() {
console.log(foo.caller);
}
foo(); // 输出调用 foo 函数的函数
// 或者使用以下代码代替 arguments 对象
function bar() {
console.log('arguments:', bar.arguments);
console.log('length:', bar.length);
}
bar(1, 2, 3); // 输出 arguments 和 length
```
请注意,如果您的代码中使用了第三方库或框架,并且它们在内部使用了 'caller', 'callee', 和 'arguments' 属性,那么您可能需要更新这些库或框架以避免这些错误。
异常:TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mo
异常:TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them。
这个异常出现的原因是在严格模式下访问了'caller','callee'和'arguments'这些属性。在webpack打包时,默认启用了严格模式,导致这两者冲突。
解决这个问题有两种方法。一种是给函数表达式一个名字或者使用函数声明来替代访问'arguments.callee'。比如将原来的代码:
```javascript
stop = requestAnimationFrame(function () {
cxt.clearRect(0, 0, canvas.width, canvas.height)
sakuraList.update()
sakuraList.draw(cxt)
stop = requestAnimationFrame(arguments.callee)
})
```
改为:
```javascript
stop = requestAnimationFrame(asd())
function asd() {
cxt.clearRect(0, 0, canvas.width, canvas.height)
sakuraList.update()
sakuraList.draw(cxt)
stop = requestAnimationFrame(asd)
}
```
另一种方法是禁用webpack打包时的严格模式,可以使用babel-plugin-transform-remove-strict-mode插件来移除严格模式。首先使用npm install babel-plugin-transform-remove-strict-mode命令下载该插件,然后在项目的.babelrc文件中引入该插件:
```javascript
"plugins": ["transform-remove-strict-mode"]
```
通过这两种方法,可以解决这个异常问题。希望对你有所帮助!<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functio](https://blog.csdn.net/weixin_42614080/article/details/105373523)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* [异常:TypeError: ‘caller‘, ‘callee‘, and ‘arguments‘ properties may not be accessed on strict ...](https://blog.csdn.net/Vixcity/article/details/128564262)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)