doubleyong
管理员
管理员
  • 最后登录2024-03-15
  • 发帖数1164
  • 最爱沙发
  • 喜欢达人
  • 原创写手
  • 社区居民
  • 忠实会员
阅读:6034回复:0

[javascript]JS报错-Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on...

楼主#
更多 发布于:2020-08-05 09:19
问题:报错信息:Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them;


代码如下:
const arr = this.props.user.user.menuInfo.reduce(function (pre,item){
           const callee = arguments.callee //将运行函数赋值给一个变量备用
           pre.push(item)
           if(item.menuChilds && item.menuChilds.length > 0) item.menuChilds.reduce(callee,pre); //判断当前参数中是否存在children,有则递归处理
           return pre;
       },[]).map((item) => {
           item.menuChilds = []
           return item
       })


原因:严格模式下,'caller', 'callee' 和  'arguments'不被允许


解决方案:换一种方式写了

代码如下:
const arr = this.props.user.user.menuInfo.reduce(function f(pre,item){
           pre.push(item)
           if(item.menuChilds && item.menuChilds.length > 0) item.menuChilds.reduce(f,pre); //判断当前参数中是否存在children,有则递归处理
           return pre;
       },[]).map((item) => {
           item.menuChilds = []
           return item
       })


参考:https://blog.csdn.net/qq_33242126/article/details/100774404
知识需要管理,知识需要分享
游客


返回顶部

公众号

公众号