异常:TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mo
时间: 2023-11-08 18:18:28 浏览: 108
异常: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 ]