阅读:6034回复:0
[javascript]JS报错-Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on...
问题:报错信息: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 |
|
|